Given an integer array having distinct elements, find the surpasser count for each element in it. In other words, for each array element, find the total number of elements to its right, which are greater than it.

0

 Given an integer array having distinct elements, find the surpasser count for each element in it. In other words, for each array element, find the total number of elements to its right, which are greater than it.



Cpp Program Code:


The getSurpasserCount() function takes an input array arr and returns a vector of integers, where each element represents the surpasser count for the corresponding element in the input array. The function initializes the count vector with zeros and then uses two nested loops to compare each pair of elements in the array. If the element at index j is greater than the element at index i, the function increments the surpasser count for the element at index i. Finally, the function returns the count vector.

In the main() function, we initialize the input array arr and call the getSurpasserCount() function to obtain the surpasser count for each element in the array. We then print the output vector to the console.

Python Program code:


The get_surpasser_count() function takes an input array arr and returns a list of integers, where each element represents the surpasser count for the corresponding element in the input array. The function initializes the count list with zeros and then uses two nested loops to compare each pair of elements in the array. If the element at index j is greater than the element at index i, the function increments the surpasser count for the element at index i. Finally, the function returns the count list.

In the main code, we initialize the input array arr and call the get_surpasser_count() function to obtain the surpasser count for each element in the array. We then print the output list to the console.

Post a Comment

0Comments
Post a Comment (0)