Find index of first occurrence of least element greater than key in array * Returns : an index in range [ 0 , n - 1 ] if key is not the greatest element in array , * - 1 if key is the greatest element in array
int leastgreater ( int low , int high , int key ) { int ans = -1 ; while ( low <= high ) { int mid = low + ( high - low + 1 ) / 2 ; int midVal = a [ mid ] ; if ( midVal < key ) {