Solve sliding window and tree BFS | Meta Interview Question