Find Surpasser Count of each element in array | Function to find surpasser count of each element in array ; stores surpasser count for element arr [ i ] ; Function to print an array ; Driver Code
function findSurpasser ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { let count = 0 ; for ( let j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ; document . write ( count + " " ) ; } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( ) ; } let arr = [ 2 , 7 , 5 , 3 , 0 , 8 , 1 ] ; let n = arr . length ; document . write ( " " + " " ) ; printArray ( arr , n ) ; document . write ( " " ) ; document . write ( " " + " " + " " ) ; findSurpasser ( arr , n ) ;