Pergunta de entrevista da empresa Two Sigma

some bfs dfs question with math and binary search