If target lies beyond the max element , than the index of strictly smaller value than target should be ( end - 1 )
if ( $ target > $ arr [ $ end ] ) return $ end ; $ ans = -1 ; while ( $ start <= $ end ) { $ mid = ( int ) ( ( $ start + $ end ) / 2 ) ;