ByteDance Interview Question

BFS / DFS traversal, moderate difficulty