Java implementation of the above approach
import java . util . * ; class GfG { public static void countOfGreaterElements ( int arr [ ] ) { int n = arr . length ; TreeMap < Integer , Integer > mp = new TreeMap < Integer , Integer > ( Collections . reverseOrder ( ) ) ;