C # program for the above approach
using System ; using System . Collections . Generic ; class GFG { static int upper_bound ( int [ ] arr , int key ) { int l = - 1 , r = arr . Length ; while ( l + 1 < r ) { int m = ( l + r ) >> 1 ; if ( arr [ m ] <= key ) l = m ; else r = m ; } return l + 1 ; }