Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Binary tree right side view and Lowest common ancestor



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Right Side View of a Binary Tree

Right Side View of a Binary Tree

Problem Statement

Consider a binary tree. If you look at it from the right-hand side, return a list of values of the nodes that are visible from the top to the bottom.

Examples

Example 1:
Input: [10, 5, 15, null, 7, null, 20]
Output: [10, 15, 20]
Explanation:
      10        <---
     /  \
    5    15     <---
     \     \
      7     20  <---
Example 2:
Input: [3, 9, 8, 4, null, null, 7]
Output: [3, 8, 7]
Explanation:
      3         <---
     / \
    9   8       <---
   /     \
  4       7     <---

Constraints

  • The number of nodes in the tree is between 0 and 1200.
  • Node values range from -150 to 150.