Lower_bound function
function lower_bound ( arr , key ) { let low = 0 ; let high = arr . length - 1 ; while ( low < high ) { let mid = low + Math . floor ( ( high - low ) / 2 ) ; if ( arr [ mid ] >= key ) { high = mid ; } else { low = mid + 1 ; } } return low ; }