BFS gives you 3920157. Perfect order. But the problem wants 3,920,157. Which nodes belong to which level? The queue knows -- but only if you ask at the right moment.
Given a binary tree, return the values of its nodes grouped by depth level -- top to bottom, left to right within each level. Then: return only the rightmost visible node at each level (what you'd see standing on the right side looking left).
[[3], [9, 20], [15, 7]]
[3, 20, 7]
Plain BFS visits every node in the right order -- 3, 9, 20, 15, 7. But it gives you a FLAT list. The queue erases the level boundary the moment it processes the next node. Somehow you need to know “the level just ended” while the queue keeps growing.
I'm running plain BFS. After processing the root (3), the queue holds 920. I process 9 and 20. What does the queue hold now -- and how would you know the level just ended?