Find number of elements in Y [ ] with values greater than x getting upperbound of x with binary search
int idx = Arrays . binarySearch ( Y , x ) ; int ans ; if ( idx < 0 ) { idx = Math . abs ( idx + 1 ) ; ans = Y . length - idx ; } else { while ( idx < n && Y [ idx ] == x ) { idx ++ ; } ans = Y . length - idx ; }