C # implementation of above approach
using System ; using System . Collections . Generic ; class GFG { static int upperBound ( List < int > a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) { high = middle ; } else { low = middle + 1 ; } } return low ; }