Pergunta de entrevista da empresa Braze

Grid BFS and sorting related problem