FastPrepLeft View of a Binary Tree
Problems/Left View of a Binary Tree

Left View of a Binary Tree

Mygate logoMygate● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Mygate phone screen for a full-time role. The report names a left-view task on a tree but leaves out the full tree model and the limits. We filled those in.

Our version is about 90% the same as the reported question.

Given the root of a binary tree, return its left view as a list of node values from top to bottom.

At each depth, include the leftmost existing node when the nodes at that depth are ordered from left to right. Include one value for every nonempty depth, even when values repeat.

An empty tree returns an empty list. The tree is displayed in level order, using null for missing children.

Function

leftView(root: TreeNode) → List<Integer>

Examples

Example 1

root = [1,2,3,null,4,5,6]return = [1,2,4]
root
124356

The first nodes at depths 0, 1, and 2 have values 1, 2, and 4.

Example 2

root = [8,null,9,null,10]return = [8,9,10]
root
8910

There is one existing node at each depth. All three are visible despite having only right-child links.

Constraints

  • The tree has 0 to 5000 nodes.
  • Each node value is an integer in [-10^6, 10^6].
  • Each node has at most two children, and the input is a valid tree with no cycles or shared child nodes.

More Mygate Phone Screen questions

  • Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
  • Maximum Subarray SumPHONE SCREEN · Seen Sep 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Sep 2026
  • Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
  • Elements Occurring More Than n/3 TimesPHONE SCREEN · Seen Jan 2025
  • Frog Jump: Minimum EnergyPHONE SCREEN · Seen Jan 2025
  • Two SumPHONE SCREEN · Seen Aug 2024
  • Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024
  • Minimum Subarray SumPHONE SCREEN · Seen Sep 2023
  • Remove the Nth Node from the EndPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions
  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Mirror a Binary TreeAdobe · PHONE SCREENAdobe interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Tree Height After Child PromotionSnowflake · PHONE SCREENSnowflake interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Tree DiameterQualcomm · PHONE SCREENQualcomm interview questions
  • Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
  • Distance Between Two Nodes in a Binary TreeBloomberg LP · PHONE SCREENBloomberg LP interview questions
All Mygate interview questionsSee Mygate hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> leftView(TreeNode root) {
        // Return the leftmost node value at every depth.
    }
}
Checking account…