Count greater elements on the left side of every array element | C # program to implement the above approach ; Function to print the count of greater elements on left of each array element ; Function to get the count of greater elements on left of each array element ; Store distinct array elements in sorted order ; Stores the count of greater elements on the left side ; Traverse the array ; Insert array elements into the set ; Find previous greater element ; Find the distance between the previous greater element of arr [ i ] and last element of the set ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void display ( int [ ] countLeftGreater , int N ) { for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( countLeftGreater [ i ] + " ▁ " ) ; } } static void countGreater ( int [ ] arr , int N ) { List < int > St = new List < int > ( ) ; int [ ] countLeftGreater = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { St . Add ( arr [ i ] ) ; int it = 0 ; St . Sort ( ) ; foreach ( int itr in St ) { if ( arr [ i ] < itr ) { break ; } it ++ ; } countLeftGreater [ i ] = Math . Abs ( it - St . Count ) ; } display ( countLeftGreater , N ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 12 , 1 , 2 , 3 , 0 , 11 , 4 } ; int N = arr . Length ; countGreater ( arr , N ) ; } }