If mid is empty , search in both sides of mid and find the closest non - empty string , and set mid accordingly .
int left = mid - 1 ; int right = mid + 1 ; while ( true ) { if ( left < first && right > last ) return -1 ; if ( right <= last && ! arr [ right ] . empty ( ) ) { mid = right ; break ; } if ( left >= first && ! arr [ left ] . empty ( ) ) { mid = left ; break ; } right ++ ; left -- ; } }