If mid is empty , search in both sides of mid and find the closest non - empty string , and set mid accordingly .
left , right = mid - 1 , mid + 1 NEW_LINE while True : NEW_LINE INDENT if left < first and right > last : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if right <= last and len ( arr [ right ] ) != 0 : NEW_LINE INDENT mid = right NEW_LINE break NEW_LINE DEDENT if left >= first and len ( arr [ left ] ) != 0 : NEW_LINE INDENT mid = left NEW_LINE break NEW_LINE DEDENT right += 1 NEW_LINE left -= 1 NEW_LINE DEDENT