binary search with switch turn on/off. works for naive cases