Braze Interview Question

Grid BFS and sorting related problem