Search function for searching the first element of the subarray which is greater or equal to the last element ( num )
< ? php function binarySearch ( $ searchSpace , $ s , $ e , $ num ) { $ ans = 0 ; while ( $ s <= $ e ) { $ mid = ( $ s + $ e ) / 2 ; if ( $ searchSpace [ $ mid ] >= $ num ) { $ ans = $ mid ; $ e = $ mid - 1 ; } else { $ s = $ mid + 1 ; } } return $ ans ; }