Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

root =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

In level-order traversal, the last node processed per level is the rightmost visible node.

Approach

BFS by levels. For each level, append the value of the last node popped.

Why it works

BFS groups nodes by depth; within a depth, the rightmost node is the one seen from the right side.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

In level-order traversal, the last node processed per level is the rightmost visible node.

Approach

BFS by levels. For each level, append the value of the last node popped.

Why it works

BFS groups nodes by depth; within a depth, the rightmost node is the one seen from the right side.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)