Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Find Surpasser Count of each element in array in C++
Suppose one array A is given. We have to find a number of surpasser of each element in that array. The surpassers are greater elements which are present at the right side of the array of the current element. Suppose A = {2, 7, 5, 3, 0, 8, 1}, the surpassers are {4, 1, 1, 1, 2, 0, 0}, so 2 has 4 numbers at right side, which are greater than 4, and the same rule for others. The solution is very simple, two nested loops will be there, for each element, it will count surpassers, then store them into another array.
Example
#includeusing namespace std; void gerSurpassers(int arr[], int surpassers[], int n){ for(int i = 0; i arr[i]) count++; } surpassers[i] = count; } } void displayArray(int arr[], int n){ for(int i = 0; i Output
Elements :2 7 5 3 0 8 1 Surpassers:4 1 1 1 2 0 0
Advertisements
