LogIn
I don't have account.
Sponsored -53%
Zebronics #1 Best Seller

ZEBRONICS Blanc Slim Wireless Mouse — Rechargeable, BT + 2.4GHz (Black)

Up to 1600 DPI · Silent clicks · 63g · Multicolor LED

★★★★★ 4.0 (9,512) 5K+ bought last month
₹376 M.R.P. ₹799Save ₹423
Buy Now
Adℹ

Left View of a Binary Tree: DFS and BFS Approaches Explained

DevSniper
21 Views

#tree

#binary-tree

#b-tree

#treemap

#depth-first-search

#breadth-first-search

Amazon Pay offer
Adℹ

There's a specific kind of interview moment that catches a lot of people off guard: the interviewer asks for the left view of a binary tree, you write a solution that looks completely reasonable, run it mentally against the tree on the whiteboard... and it quietly returns the right view instead. Not a crash, not an obviously wrong answer just a plausible-looking list of numbers that happens to be exactly backwards. This article walks through why that mix-up happens so easily and how to build a version that gets it right every time.

Problem Statement

You are given the root of a binary tree. Imagine standing to the left of the tree and looking straight across the left view is the set of nodes you'd actually be able to see from that angle.

More precisely: for every level of the tree, the left view keeps only the node that's furthest to the left at that level. Any other node at that same level, sitting behind it from this angle, is left out.

Given the root of a binary tree, return its left view as a list of values, ordered from the topmost level to the bottommost.

For example, for a tree shaped like this:

                10
              /    \
            20       30
              \        \
               40       50
              /            \
            60              70

The left view is:

10, 20, 40, 60

Understanding the Problem First

It's worth pausing on one thing before writing any code: left view groups nodes by level (depth), not by horizontal distance. This is a genuinely common point of confusion, because Top view and Bottom view two closely related problems are built entirely around horizontal distance instead. Left view doesn't care how far left or right a node has drifted; it only cares how deep it is and whether it's the first node encountered at that depth when scanning left to right.

For the tree above:

  • Depth 0: just 10.
  • Depth 1: 20 and 30. 20 is further left, so it wins.
  • Depth 2: 40 and 50. 40 is further left, so it wins.
  • Depth 3: 60 and 70. 60 is further left, so it wins.

So the problem comes down to: for every depth, find the leftmost node, then read those winners off from the shallowest depth to the deepest. Every approach below is a different way of visiting nodes and deciding whether the one in hand should be allowed to claim its depth.

Setting Up the Tree

We'll use the tree from above throughout this article.

class TreeNode {
    int val;
    TreeNode left, right;

    TreeNode(int val) {
        this.val = val;
    }
}
public class SampleTree {
    public static TreeNode build() {
        TreeNode n10 = new TreeNode(10);
        TreeNode n20 = new TreeNode(20);
        TreeNode n30 = new TreeNode(30);
        TreeNode n40 = new TreeNode(40);
        TreeNode n50 = new TreeNode(50);
        TreeNode n60 = new TreeNode(60);
        TreeNode n70 = new TreeNode(70);

        n10.left = n20;
        n10.right = n30;
        n20.right = n40;
        n30.right = n50;
        n40.left = n60;
        n50.right = n70;

        return n10;
    }
}

Approach 1: The Naive Attempt (and How It Secretly Becomes Right View)

Here's a first instinct that feels almost obviously correct: run a DFS, always visiting the left child before the right child, track each node's depth as you go and write its value into a map keyed by depth overwriting whatever's already there. Since we're always exploring left before right, surely the map ends up holding the leftmost node at each depth... right?

The flaw is subtle: overwriting unconditionally means the map doesn't actually end up holding the first node visited at each depth it ends up holding the last one. And those are very different things.

Tracing Through It

A preorder DFS (root, then left subtree, then right subtree) visits our tree in this order:

10 → 20 → 40 → 60 → 30 → 50 → 70

Overwriting the map at every visit:

Visit Node Depth Map after this step
1 10 0 {0: 10}
2 20 1 {0: 10, 1: 20}
3 40 2 {..., 2: 40}
4 60 3 {..., 3: 60}
5 30 1 {1: 30, ...}
6 50 2 {2: 50, ...}
7 70 3 {3: 70, ...}

Because preorder DFS fully finishes exploring the left subtree before it ever touches the right subtree, every node in the right subtree 30, 50, 70 gets visited after its entire left-side counterpart and ends up overwriting a correct answer with an incorrect one.

The naive output is:

10, 30, 50, 70

Look closely at that list. It isn't a random wrong answer it's the right view of this exact tree. The unconditional-overwrite bug doesn't fail randomly; it consistently produces the mirror-image answer, because "the last node visited at each depth" is precisely the definition of right view, not left view. That's what makes this particular bug so easy to miss in an interview: the output looks completely plausible, it's just answering a different question than the one that was asked.

Approach 2: DFS With "First Occurrence Wins" (Correct)

The fix here turns out to be simpler than you might expect and simpler than the equivalent fix for top view. Instead of tracking each node's depth and comparing it against the current occupant, we only need to ask one question: has this depth already been claimed? If not, this node claims it. If it has, we skip and move on no comparison, no depth field, nothing to overwrite.

This works because preorder DFS always visits a node's left subtree completely before its right subtree, at every level of recursion, all the way down. That means the first node reached at any given depth is guaranteed to be the leftmost one there's no scenario where a right-side branch reaches a depth before the corresponding left-side branch does, since the traversal simply hasn't gotten there yet.

Tracing Through It

Same preorder traversal 10 → 20 → 40 → 60 → 30 → 50 → 70 now only recording a depth the first time it's seen:

Visit Node Depth Already claimed? Map after this step
1 10 0 no → add {0: 10}
2 20 1 no → add {..., 1: 20}
3 40 2 no → add {..., 2: 40}
4 60 3 no → add {..., 3: 60}
5 30 1 yes → skip unchanged
6 50 2 yes → skip unchanged
7 70 3 yes → skip unchanged

Reading the map from the shallowest depth to the deepest:

10, 20, 40, 60

the correct answer.

 
#include <bits/stdc++.h>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int v) : val(v), left(nullptr), right(nullptr) {}
};

void fillLevels(TreeNode* node, int depth, vector<int>& result) {
    if (node == nullptr) return;
    // The first node we reach at a given depth is always the
    // leftmost one, thanks to visiting left before right
    if (depth == (int)result.size()) {
        result.push_back(node->val);
    }
    fillLevels(node->left, depth + 1, result);
    fillLevels(node->right, depth + 1, result);
}

vector<int> leftView(TreeNode* root) {
    vector<int> result;
    fillLevels(root, 0, result);
    return result;
}

int main() {
    TreeNode* root = SampleTree::build();
    vector<int> result = leftView(root);
    for (int v : result) cout << v << " ";
    cout << endl;
    // Output: 10 20 40 60
    return 0;
}
 
using System;
using System.Collections.Generic;

public class LeftViewDFS {
    public static List<int> LeftView(TreeNode root) {
        List<int> result = new List<int>();
        FillLevels(root, 0, result);
        return result;
    }
    private static void FillLevels(TreeNode node, int depth, List<int> result) {
        if (node == null) return;
        // The first node we reach at a given depth is always the
        // leftmost one, thanks to visiting left before right
        if (depth == result.Count) {
            result.Add(node.val);
        }
        FillLevels(node.left, depth + 1, result);
        FillLevels(node.right, depth + 1, result);
    }
    public static void Main(string[] args) {
        TreeNode root = SampleTree.Build();
        List<int> result = LeftView(root);
        Console.WriteLine(string.Join(", ", result));
        // Output: 10, 20, 40, 60
    }
}
 
import java.util.*;
public class LeftViewDFS {
    public static List<Integer> leftView(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        fillLevels(root, 0, result);
        return result;
    }
    private static void fillLevels(TreeNode node, int depth, List<Integer> result) {
        if (node == null) return;
        // The first node we reach at a given depth is always the
        // leftmost one, thanks to visiting left before right
        if (depth == result.size()) {
            result.add(node.val);
        }
        fillLevels(node.left, depth + 1, result);
        fillLevels(node.right, depth + 1, result);
    }
    public static void main(String[] args) {
        TreeNode root = SampleTree.build();
        System.out.println(leftView(root));
        // Output: [10, 20, 40, 60]
    }
}
 
def fill_levels(node, depth, result):
    if node is None:
        return
    # The first node we reach at a given depth is always the
    # leftmost one, thanks to visiting left before right
    if depth == len(result):
        result.append(node.val)
    fill_levels(node.left, depth + 1, result)
    fill_levels(node.right, depth + 1, result)

def left_view(root):
    result = []
    fill_levels(root, 0, result)
    return result

if __name__ == "__main__":
    root = SampleTree.build()
    result = left_view(root)
    print(result)
    # Output: [10, 20, 40, 60]

Notice there's no map at all here just a growing List, where depth == result.size() is a cheap way of asking "have we already recorded something at this depth?" It's a small detail, but it's only possible because depth values are sequential non-negative integers, unlike the horizontal distances used in top and bottom view, which can run negative and out of order.

Complexity

Value
Time O(n) every node is visited once and the depth check is a constant-time list-size comparison
Space O(h) for the recursion stack, where h is the tree's height

Approach 3: BFS / Level Order Traversal (Optimal)

BFS makes the whole problem almost self-evident. Since a level order traversal processes one full level at a time, left to right, the leftmost node at any level is simply the first node dequeued during that level's turn. There's no bug to accidentally invert here, because there's no traversal-order subtlety to get wrong in the first place the level boundaries are explicit.

Tracing Through It

Processing the tree level by level:

Level Nodes in this level (left to right) Node taken for left view
0 10 10
1 20, 30 20
2 40, 50 40
3 60, 70 60

Final result, read top to bottom:

10, 20, 40, 60
 
#include <bits/stdc++.h>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int v) : val(v), left(nullptr), right(nullptr) {}
};

vector<int> leftView(TreeNode* root) {
    vector<int> result;
    if (root == nullptr) return result;
    queue<TreeNode*> q;
    q.push(root);
    while (!q.empty()) {
        int levelSize = q.size();
        for (int i = 0; i < levelSize; i++) {
            TreeNode* current = q.front();
            q.pop();
            // The first node processed in this level is the leftmost one
            if (i == 0) {
                result.push_back(current->val);
            }
            if (current->left != nullptr) {
                q.push(current->left);
            }
            if (current->right != nullptr) {
                q.push(current->right);
            }
        }
    }
    return result;
}

int main() {
    TreeNode* root = SampleTree::build();
    vector<int> result = leftView(root);
    for (int v : result) cout << v << " ";
    cout << endl;
    // Output: 10 20 40 60
    return 0;
}
 
using System;
using System.Collections.Generic;

public class LeftViewBFS {
    public static List<int> LeftView(TreeNode root) {
        List<int> result = new List<int>();
        if (root == null) return result;
        Queue<TreeNode> queue = new Queue<TreeNode>();
        queue.Enqueue(root);
        while (queue.Count > 0) {
            int levelSize = queue.Count;
            for (int i = 0; i < levelSize; i++) {
                TreeNode current = queue.Dequeue();
                // The first node processed in this level is the leftmost one
                if (i == 0) {
                    result.Add(current.val);
                }
                if (current.left != null) {
                    queue.Enqueue(current.left);
                }
                if (current.right != null) {
                    queue.Enqueue(current.right);
                }
            }
        }
        return result;
    }
    public static void Main(string[] args) {
        TreeNode root = SampleTree.Build();
        List<int> result = LeftView(root);
        Console.WriteLine(string.Join(", ", result));
        // Output: 10, 20, 40, 60
    }
}
 
import java.util.*;

public class LeftViewBFS {
    public static List<Integer> leftView(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        if (root == null) return result;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            int levelSize = queue.size();
            for (int i = 0; i < levelSize; i++) {
                TreeNode current = queue.poll();
                // The first node processed in this level is the leftmost one
                if (i == 0) {
                    result.add(current.val);
                }
                if (current.left != null) {
                    queue.add(current.left);
                }
                if (current.right != null) {
                    queue.add(current.right);
                }
            }
        }
        return result;
    }
    public static void main(String[] args) {
        TreeNode root = SampleTree.build();
        System.out.println(leftView(root));
        // Output: [10, 20, 40, 60]
    }
}
 
from collections import deque

def left_view(root):
    result = []
    if root is None:
        return result
    queue = deque([root])
    while queue:
        level_size = len(queue)
        for i in range(level_size):
            current = queue.popleft()
            # The first node processed in this level is the leftmost one
            if i == 0:
                result.append(current.val)
            if current.left is not None:
                queue.append(current.left)
            if current.right is not None:
                queue.append(current.right)
    return result

if __name__ == "__main__":
    root = SampleTree.build()
    result = left_view(root)
    print(result)
    # Output: [10, 20, 40, 60]

Complexity

Value
Time O(n) every node is enqueued and dequeued exactly once
Space O(n) for the queue in the worst case, when the tree's widest level holds close to n / 2 nodes

Comparing All Approaches

Approach Time Complexity Space Complexity Core Idea
Naive DFS (buggy) O(n) O(h) Overwrite the map on every visit ends up keeping the last node seen per depth, which is actually the right view
DFS with "First Occurrence Wins" O(n) O(h) Record a depth only the first time it's reached safe because preorder always finishes the left subtree before the right
BFS / Level Order Optimal O(n) O(n) Take the first node dequeued at each level directly no traversal-order reasoning required

n = number of nodes, h = height of the tree.

One thing worth calling out if you've also worked through top view or bottom view: those problems need a TreeMap and pay an O(log w) cost per node, because horizontal distance can run negative and isn't visited in any guaranteed order. Left view sidesteps that entirely depth is always a small non-negative integer processed in a predictable order, so both correct solutions here run in clean O(n), with no logarithmic factor at all.

It's also worth being explicit about the trap in Approach 1: it's not that the naive method produces garbage it produces a coherent, correct-looking answer to the wrong problem. That's exactly the kind of bug that survives a quick self-check and only gets caught when someone compares it against the actual expected output.

Key Takeaways

  1. "Left before right" in your traversal doesn't automatically mean "leftmost node wins." Approach 1 visits left before right too it just doesn't do anything with that ordering, so the overwrite erases the benefit entirely.
  2. A wrong answer that looks right is more dangerous than one that looks wrong. The naive approach here doesn't fail loudly; it silently computes right view instead, which is easy to miss without a second example to test against.
  3. Not every "view" problem needs the same toolkit. Top and bottom view need horizontal distance and a sorted map; left view only needs depth and a simple "seen it yet" check recognizing which kind of grouping a problem actually needs saves real implementation effort.
  4. BFS is often the safer default for level-based problems. When a traversal order subtlety is easy to get backwards in DFS, level order traversal frequently removes the ambiguity by making level boundaries explicit.

Frequently Asked Questions

1. What is the difference between left view and top view of a binary tree?

Left view groups nodes by depth (level) and keeps the leftmost node at each level. Top view groups nodes by horizontal distance from the root and keeps the shallowest node at each horizontal distance. They're built on different groupings and can return different results for the same tree.

2. Why does a naive DFS solution for left view sometimes return the right view instead?

If the implementation overwrites a depth's recorded value on every visit instead of only on the first visit, the last node visited at each depth ends up being kept. In a standard left-before-right preorder traversal, the last node visited at any depth always comes from the rightmost branch which is exactly the definition of right view.

3. Does finding the left view require tracking horizontal distance?

No. Left view only depends on depth and left-to-right position within a level, so it can be solved without any horizontal distance calculation at all unlike top view or bottom view.

4. What is the time complexity of finding the left view of a binary tree?

Both the correct DFS approach and the BFS approach run in O(n) time, where n is the number of nodes. Unlike top and bottom view, no TreeMap or sorting step is needed, since depth values are already sequential.

5. Is BFS or DFS better for solving left view?

Both run in O(n) time. BFS is generally considered more intuitive here because level boundaries are explicit in a queue-based traversal, making it harder to accidentally build the right view instead. The DFS approach is equally correct once you record only the first node seen at each depth.

Related Articles

Responses (0)

Write a response

CommentHide Comments

No Comments yet.

"},"4":{"id":4,"name":"ZEBRONICS Blanc mouse ad","otherData":"{}","contentFormat":2,"content":"
Sponsored -53%
Zebronics #1 Best Seller

ZEBRONICS Blanc Slim Wireless Mouse — Rechargeable, BT + 2.4GHz (Black)

Up to 1600 DPI · Silent clicks · 63g · Multicolor LED

★★★★★ 4.0 (9,512) 5K+ bought last month
₹376 M.R.P. ₹799Save ₹423
Buy Now
"},"2":{"id":2,"name":"Crousal Ads","otherData":"{}","contentFormat":2,"content":"
Sponsored -34%
iQOO Amazon's Choice

iQOO Z10 Lite 5G — Cyber Green, 4GB RAM, 128GB Storage

Dimensity 6300 · 50MP Sony AI Camera · 6000 mAh · IP64

★★★★★ 4.0 (2,052) 500+ bought last month
₹18,997 M.R.P. ₹28,999Save ₹10,002
Buy Now
"},"1":{"id":1,"name":"Banner Ads","otherData":"{}","contentFormat":2,"content":"\n
\n \n \n \"Amazon\n \n
"}}},"blogDetails":{"isWriter":false,"likes":0,"isLikedByUser":false,"tagIds":[21,27,32,43,133,177,282,316,317],"tags":[{"id":21,"name":"Tree","maskingName":"tree","isFeatured":false},{"id":27,"name":"Binary Tree","maskingName":"binary-tree","isFeatured":false},{"id":32,"name":"B-Tree","maskingName":"b-tree","isFeatured":false},{"id":43,"name":"HashMap","maskingName":"hashmap","isFeatured":true},{"id":133,"name":"Coding Problems","maskingName":"coding-problems","isFeatured":true},{"id":177,"name":"DSA","maskingName":"dsa","isFeatured":true},{"id":282,"name":"TreeMap","maskingName":"treemap","isFeatured":false},{"id":316,"name":"DFS","maskingName":"depth-first-search","isFeatured":false},{"id":317,"name":"BFS","maskingName":"breadth-first-search","isFeatured":false}],"comments":[],"bookmark":{"isBookmarked":false,"count":0},"author":{"userId":"MjlfNF84LVsyXTJuLXRDX0FOZ2VfX0l0","name":"DevSniper"},"viewCount":20,"showBannerImage":false,"seoTags":"Left View of Binary Tree, binary tree left view, left view of binary tree DFS, left view of binary tree BFS, binary tree interview questions, tree traversal algorithms, level order traversal, preorder traversal, DFS tree traversal, BFS tree traversal, binary tree problems, DSA tree problems, leftmost node at each level, tree view algorithms, coding interview preparation, data structures and algorithms, binary tree coding questions, recursive tree traversal, tree interview questions, solve left view binary tree","content":"

There's a specific kind of interview moment that catches a lot of people off guard: the interviewer asks for the left view of a binary tree, you write a solution that looks completely reasonable, run it mentally against the tree on the whiteboard... and it quietly returns the right view instead. Not a crash, not an obviously wrong answer just a plausible-looking list of numbers that happens to be exactly backwards. This article walks through why that mix-up happens so easily and how to build a version that gets it right every time.

\n

Problem Statement

\n

You are given the root of a binary tree. Imagine standing to the left of the tree and looking straight across the left view is the set of nodes you'd actually be able to see from that angle.

\n

More precisely: for every level of the tree, the left view keeps only the node that's furthest to the left at that level. Any other node at that same level, sitting behind it from this angle, is left out.

\n

Given the root of a binary tree, return its left view as a list of values, ordered from the topmost level to the bottommost.

\n

For example, for a tree shaped like this:

\n
                10\n              /    \\\n            20       30\n              \\        \\\n               40       50\n              /            \\\n            60              70\n
\n

The left view is:

\n
10, 20, 40, 60\n
\n

Understanding the Problem First

\n

It's worth pausing on one thing before writing any code: left view groups nodes by level (depth), not by horizontal distance. This is a genuinely common point of confusion, because Top view and Bottom view two closely related problems are built entirely around horizontal distance instead. Left view doesn't care how far left or right a node has drifted; it only cares how deep it is and whether it's the first node encountered at that depth when scanning left to right.

\n

For the tree above:

\n\n

So the problem comes down to: for every depth, find the leftmost node, then read those winners off from the shallowest depth to the deepest. Every approach below is a different way of visiting nodes and deciding whether the one in hand should be allowed to claim its depth.

\n

Setting Up the Tree

\n

We'll use the tree from above throughout this article.

\n
class TreeNode {\n    int val;\n    TreeNode left, right;\n\n    TreeNode(int val) {\n        this.val = val;\n    }\n}\n
\n
public class SampleTree {\n    public static TreeNode build() {\n        TreeNode n10 = new TreeNode(10);\n        TreeNode n20 = new TreeNode(20);\n        TreeNode n30 = new TreeNode(30);\n        TreeNode n40 = new TreeNode(40);\n        TreeNode n50 = new TreeNode(50);\n        TreeNode n60 = new TreeNode(60);\n        TreeNode n70 = new TreeNode(70);\n\n        n10.left = n20;\n        n10.right = n30;\n        n20.right = n40;\n        n30.right = n50;\n        n40.left = n60;\n        n50.right = n70;\n\n        return n10;\n    }\n}\n
\n

Approach 1: The Naive Attempt (and How It Secretly Becomes Right View)

\n

Here's a first instinct that feels almost obviously correct: run a DFS, always visiting the left child before the right child, track each node's depth as you go and write its value into a map keyed by depth overwriting whatever's already there. Since we're always exploring left before right, surely the map ends up holding the leftmost node at each depth... right?

\n

The flaw is subtle: overwriting unconditionally means the map doesn't actually end up holding the first node visited at each depth it ends up holding the last one. And those are very different things.

\n

Tracing Through It

\n

A preorder DFS (root, then left subtree, then right subtree) visits our tree in this order:

\n
10 → 20 → 40 → 60 → 30 → 50 → 70\n
\n

Overwriting the map at every visit:

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
VisitNodeDepthMap after this step
1100{0: 10}
2201{0: 10, 1: 20}
3402{..., 2: 40}
4603{..., 3: 60}
5301{1: 30, ...}
6502{2: 50, ...}
7703{3: 70, ...}
\n
\n

Because preorder DFS fully finishes exploring the left subtree before it ever touches the right subtree, every node in the right subtree 30, 50, 70 gets visited after its entire left-side counterpart and ends up overwriting a correct answer with an incorrect one.

\n

The naive output is:

\n
10, 30, 50, 70\n
\n

Look closely at that list. It isn't a random wrong answer it's the right view of this exact tree. The unconditional-overwrite bug doesn't fail randomly; it consistently produces the mirror-image answer, because \"the last node visited at each depth\" is precisely the definition of right view, not left view. That's what makes this particular bug so easy to miss in an interview: the output looks completely plausible, it's just answering a different question than the one that was asked.

\n

Approach 2: DFS With \"First Occurrence Wins\" (Correct)

\n

The fix here turns out to be simpler than you might expect and simpler than the equivalent fix for top view. Instead of tracking each node's depth and comparing it against the current occupant, we only need to ask one question: has this depth already been claimed? If not, this node claims it. If it has, we skip and move on no comparison, no depth field, nothing to overwrite.

\n

This works because preorder DFS always visits a node's left subtree completely before its right subtree, at every level of recursion, all the way down. That means the first node reached at any given depth is guaranteed to be the leftmost one there's no scenario where a right-side branch reaches a depth before the corresponding left-side branch does, since the traversal simply hasn't gotten there yet.

\n

Tracing Through It

\n

Same preorder traversal 10 → 20 → 40 → 60 → 30 → 50 → 70 now only recording a depth the first time it's seen:

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
VisitNodeDepthAlready claimed?Map after this step
1100no → add{0: 10}
2201no → add{..., 1: 20}
3402no → add{..., 2: 40}
4603no → add{..., 3: 60}
5301yes → skipunchanged
6502yes → skipunchanged
7703yes → skipunchanged
\n
\n

Reading the map from the shallowest depth to the deepest:

\n
10, 20, 40, 60\n
\n

the correct answer.

\n
 \n#include <bits/stdc++.h>\nusing namespace std;\n\nstruct TreeNode {\n    int val;\n    TreeNode* left;\n    TreeNode* right;\n    TreeNode(int v) : val(v), left(nullptr), right(nullptr) {}\n};\n\nvoid fillLevels(TreeNode* node, int depth, vector<int>& result) {\n    if (node == nullptr) return;\n    // The first node we reach at a given depth is always the\n    // leftmost one, thanks to visiting left before right\n    if (depth == (int)result.size()) {\n        result.push_back(node->val);\n    }\n    fillLevels(node->left, depth + 1, result);\n    fillLevels(node->right, depth + 1, result);\n}\n\nvector<int> leftView(TreeNode* root) {\n    vector<int> result;\n    fillLevels(root, 0, result);\n    return result;\n}\n\nint main() {\n    TreeNode* root = SampleTree::build();\n    vector<int> result = leftView(root);\n    for (int v : result) cout << v << \" \";\n    cout << endl;\n    // Output: 10 20 40 60\n    return 0;\n}\n
 \nusing System;\nusing System.Collections.Generic;\n\npublic class LeftViewDFS {\n    public static List<int> LeftView(TreeNode root) {\n        List<int> result = new List<int>();\n        FillLevels(root, 0, result);\n        return result;\n    }\n    private static void FillLevels(TreeNode node, int depth, List<int> result) {\n        if (node == null) return;\n        // The first node we reach at a given depth is always the\n        // leftmost one, thanks to visiting left before right\n        if (depth == result.Count) {\n            result.Add(node.val);\n        }\n        FillLevels(node.left, depth + 1, result);\n        FillLevels(node.right, depth + 1, result);\n    }\n    public static void Main(string[] args) {\n        TreeNode root = SampleTree.Build();\n        List<int> result = LeftView(root);\n        Console.WriteLine(string.Join(\", \", result));\n        // Output: 10, 20, 40, 60\n    }\n}\n
 \nimport java.util.*;\npublic class LeftViewDFS {\n    public static List<Integer> leftView(TreeNode root) {\n        List<Integer> result = new ArrayList<>();\n        fillLevels(root, 0, result);\n        return result;\n    }\n    private static void fillLevels(TreeNode node, int depth, List<Integer> result) {\n        if (node == null) return;\n        // The first node we reach at a given depth is always the\n        // leftmost one, thanks to visiting left before right\n        if (depth == result.size()) {\n            result.add(node.val);\n        }\n        fillLevels(node.left, depth + 1, result);\n        fillLevels(node.right, depth + 1, result);\n    }\n    public static void main(String[] args) {\n        TreeNode root = SampleTree.build();\n        System.out.println(leftView(root));\n        // Output: [10, 20, 40, 60]\n    }\n}\n
 \ndef fill_levels(node, depth, result):\n    if node is None:\n        return\n    # The first node we reach at a given depth is always the\n    # leftmost one, thanks to visiting left before right\n    if depth == len(result):\n        result.append(node.val)\n    fill_levels(node.left, depth + 1, result)\n    fill_levels(node.right, depth + 1, result)\n\ndef left_view(root):\n    result = []\n    fill_levels(root, 0, result)\n    return result\n\nif __name__ == \"__main__\":\n    root = SampleTree.build()\n    result = left_view(root)\n    print(result)\n    # Output: [10, 20, 40, 60]\n
\n

Notice there's no map at all here just a growing List, where depth == result.size() is a cheap way of asking \"have we already recorded something at this depth?\" It's a small detail, but it's only possible because depth values are sequential non-negative integers, unlike the horizontal distances used in top and bottom view, which can run negative and out of order.

\n

Complexity

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Value
TimeO(n) every node is visited once and the depth check is a constant-time list-size comparison
SpaceO(h) for the recursion stack, where h is the tree's height
\n
\n

Approach 3: BFS / Level Order Traversal (Optimal)

\n

BFS makes the whole problem almost self-evident. Since a level order traversal processes one full level at a time, left to right, the leftmost node at any level is simply the first node dequeued during that level's turn. There's no bug to accidentally invert here, because there's no traversal-order subtlety to get wrong in the first place the level boundaries are explicit.

\n

Tracing Through It

\n

Processing the tree level by level:

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
LevelNodes in this level (left to right)Node taken for left view
01010
120, 3020
240, 5040
360, 7060
\n
\n

Final result, read top to bottom:

\n
10, 20, 40, 60\n
\n
 \n#include <bits/stdc++.h>\nusing namespace std;\n\nstruct TreeNode {\n    int val;\n    TreeNode* left;\n    TreeNode* right;\n    TreeNode(int v) : val(v), left(nullptr), right(nullptr) {}\n};\n\nvector<int> leftView(TreeNode* root) {\n    vector<int> result;\n    if (root == nullptr) return result;\n    queue<TreeNode*> q;\n    q.push(root);\n    while (!q.empty()) {\n        int levelSize = q.size();\n        for (int i = 0; i < levelSize; i++) {\n            TreeNode* current = q.front();\n            q.pop();\n            // The first node processed in this level is the leftmost one\n            if (i == 0) {\n                result.push_back(current->val);\n            }\n            if (current->left != nullptr) {\n                q.push(current->left);\n            }\n            if (current->right != nullptr) {\n                q.push(current->right);\n            }\n        }\n    }\n    return result;\n}\n\nint main() {\n    TreeNode* root = SampleTree::build();\n    vector<int> result = leftView(root);\n    for (int v : result) cout << v << \" \";\n    cout << endl;\n    // Output: 10 20 40 60\n    return 0;\n}\n
 \nusing System;\nusing System.Collections.Generic;\n\npublic class LeftViewBFS {\n    public static List<int> LeftView(TreeNode root) {\n        List<int> result = new List<int>();\n        if (root == null) return result;\n        Queue<TreeNode> queue = new Queue<TreeNode>();\n        queue.Enqueue(root);\n        while (queue.Count > 0) {\n            int levelSize = queue.Count;\n            for (int i = 0; i < levelSize; i++) {\n                TreeNode current = queue.Dequeue();\n                // The first node processed in this level is the leftmost one\n                if (i == 0) {\n                    result.Add(current.val);\n                }\n                if (current.left != null) {\n                    queue.Enqueue(current.left);\n                }\n                if (current.right != null) {\n                    queue.Enqueue(current.right);\n                }\n            }\n        }\n        return result;\n    }\n    public static void Main(string[] args) {\n        TreeNode root = SampleTree.Build();\n        List<int> result = LeftView(root);\n        Console.WriteLine(string.Join(\", \", result));\n        // Output: 10, 20, 40, 60\n    }\n}\n
 \nimport java.util.*;\n\npublic class LeftViewBFS {\n    public static List<Integer> leftView(TreeNode root) {\n        List<Integer> result = new ArrayList<>();\n        if (root == null) return result;\n        Queue<TreeNode> queue = new LinkedList<>();\n        queue.add(root);\n        while (!queue.isEmpty()) {\n            int levelSize = queue.size();\n            for (int i = 0; i < levelSize; i++) {\n                TreeNode current = queue.poll();\n                // The first node processed in this level is the leftmost one\n                if (i == 0) {\n                    result.add(current.val);\n                }\n                if (current.left != null) {\n                    queue.add(current.left);\n                }\n                if (current.right != null) {\n                    queue.add(current.right);\n                }\n            }\n        }\n        return result;\n    }\n    public static void main(String[] args) {\n        TreeNode root = SampleTree.build();\n        System.out.println(leftView(root));\n        // Output: [10, 20, 40, 60]\n    }\n}\n
 \nfrom collections import deque\n\ndef left_view(root):\n    result = []\n    if root is None:\n        return result\n    queue = deque([root])\n    while queue:\n        level_size = len(queue)\n        for i in range(level_size):\n            current = queue.popleft()\n            # The first node processed in this level is the leftmost one\n            if i == 0:\n                result.append(current.val)\n            if current.left is not None:\n                queue.append(current.left)\n            if current.right is not None:\n                queue.append(current.right)\n    return result\n\nif __name__ == \"__main__\":\n    root = SampleTree.build()\n    result = left_view(root)\n    print(result)\n    # Output: [10, 20, 40, 60]\n
\n

Complexity

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Value
TimeO(n) every node is enqueued and dequeued exactly once
SpaceO(n) for the queue in the worst case, when the tree's widest level holds close to n / 2 nodes
\n
\n

Comparing All Approaches

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ApproachTime ComplexitySpace ComplexityCore Idea
Naive DFS (buggy)O(n)O(h)Overwrite the map on every visit ends up keeping the last node seen per depth, which is actually the right view
DFS with \"First Occurrence Wins\"O(n)O(h)Record a depth only the first time it's reached safe because preorder always finishes the left subtree before the right
BFS / Level Order OptimalO(n)O(n)Take the first node dequeued at each level directly no traversal-order reasoning required
\n
\n

n = number of nodes, h = height of the tree.

\n

One thing worth calling out if you've also worked through top view or bottom view: those problems need a TreeMap and pay an O(log w) cost per node, because horizontal distance can run negative and isn't visited in any guaranteed order. Left view sidesteps that entirely depth is always a small non-negative integer processed in a predictable order, so both correct solutions here run in clean O(n), with no logarithmic factor at all.

\n

It's also worth being explicit about the trap in Approach 1: it's not that the naive method produces garbage it produces a coherent, correct-looking answer to the wrong problem. That's exactly the kind of bug that survives a quick self-check and only gets caught when someone compares it against the actual expected output.

\n

Key Takeaways

\n
    \n
  1. \"Left before right\" in your traversal doesn't automatically mean \"leftmost node wins.\" Approach 1 visits left before right too it just doesn't do anything with that ordering, so the overwrite erases the benefit entirely.
  2. \n
  3. A wrong answer that looks right is more dangerous than one that looks wrong. The naive approach here doesn't fail loudly; it silently computes right view instead, which is easy to miss without a second example to test against.
  4. \n
  5. Not every \"view\" problem needs the same toolkit. Top and bottom view need horizontal distance and a sorted map; left view only needs depth and a simple \"seen it yet\" check recognizing which kind of grouping a problem actually needs saves real implementation effort.
  6. \n
  7. BFS is often the safer default for level-based problems. When a traversal order subtlety is easy to get backwards in DFS, level order traversal frequently removes the ambiguity by making level boundaries explicit.
  8. \n
\n

Frequently Asked Questions

\n
\n

1. What is the difference between left view and top view of a binary tree?

\n

Left view groups nodes by depth (level) and keeps the leftmost node at each level. Top view groups nodes by horizontal distance from the root and keeps the shallowest node at each horizontal distance. They're built on different groupings and can return different results for the same tree.

\n

2. Why does a naive DFS solution for left view sometimes return the right view instead?

\n

If the implementation overwrites a depth's recorded value on every visit instead of only on the first visit, the last node visited at each depth ends up being kept. In a standard left-before-right preorder traversal, the last node visited at any depth always comes from the rightmost branch which is exactly the definition of right view.

\n

3. Does finding the left view require tracking horizontal distance?

\n

No. Left view only depends on depth and left-to-right position within a level, so it can be solved without any horizontal distance calculation at all unlike top view or bottom view.

\n

4. What is the time complexity of finding the left view of a binary tree?

\n

Both the correct DFS approach and the BFS approach run in O(n) time, where n is the number of nodes. Unlike top and bottom view, no TreeMap or sorting step is needed, since depth values are already sequential.

\n

5. Is BFS or DFS better for solving left view?

\n

Both run in O(n) time. BFS is generally considered more intuitive here because level boundaries are explicit in a queue-based traversal, making it harder to accidentally build the right view instead. The DFS approach is equally correct once you record only the first node seen at each depth.

\n
\n

Related Articles

\n
\n

Bottom View of a Binary Tree

\n

Top View of a Binary Tree

\n

Right View of a Binary Tree

\n
","categoryId":177,"subCategoryId":177,"contentFormat":5,"blogId":206,"userId":"MjlfNF84LVsyXTJuLXRDX0FOZ2VfX0l0","title":"Left View of a Binary Tree: DFS and BFS Approaches Explained","url":"left-view-of-a-binary-tree","bannerImage":"","seoDescription":"Learn how to find the left view of a binary tree using DFS and BFS, with examples, code, complexity analysis, common mistakes and interview tips.","generatedOn":"2026-08-28T10:15:46","updatedOn":"2026-08-28T10:15:46"},"popularContents":[{"id":135,"title":"Spinny SDE-1 Interview Experience (Selected)","url":"spinny-sde-1-interview-experience-selected","description":null,"seoDescription":"Spinny SDE-1 Interview Experience (Selected) | 4 Rounds Breakdown: Coding, LLD, Java, SQL + Real Interview Questions","contentType":5,"generatedOn":"2026-10-14T22:53:53.988434Z","viewCount":0},{"id":139,"title":"Blinkit (Eternal) SDE-1 Interview Experience (June 2026) – Offer Received","url":"blinkit-eternal-sde-1-interview-experience-june-2026-offer-received","description":null,"seoDescription":"Blinkit SDE-1 interview experience with a 30 LPA offer. Covers House Robber DP, ticket booking system design, culture fit round and tips.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9884374Z","viewCount":0},{"id":166,"title":"System Design Interview – BIGGEST Mistakes to Avoid","url":"system-design-interview-biggest-mistakes-to-avoid","description":null,"seoDescription":"Learn the biggest mistakes to avoid in a system design interview, from unclear requirements to poor trade-off analysis. Includes real-world cases, advanced insights and examples to help you ace your next system design interview.","contentType":2,"generatedOn":"2026-10-14T22:53:53.9879853Z","viewCount":0},{"id":138,"title":"DSA Patterns for Coding Interviews: Complete LeetCode Roadmap (Beginner to Advanced)","url":"dsa-patterns-for-coding-interviews-complete-leetcode-roadmap-beginner-to-advanced","description":null,"seoDescription":"Master every LeetCode pattern for coding interviews. Learn Arrays, Sliding Window, Graphs, Dynamic Programming, Trees, Heaps and more with 250+ curated problem","contentType":5,"generatedOn":"2026-10-14T22:53:53.9884358Z","viewCount":0},{"id":173,"title":"Uber SDE-2 Interview Experience : LLD, HLD, DSA & Hiring Manager Round","url":"uber-sde-2-interview-experience-lld-hld-dsa-hiring-manager-round","description":null,"seoDescription":"Read a real Uber SDE-2 interview experience covering DSA, low-level design, high-level system design, behavioral rounds, hiring freeze and key takeaways.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9884454Z","viewCount":0},{"id":122,"title":"Zepto SDE-1 Interview Experience (Backend Developer) : Real DSA, LLD, Chess Game Design","url":"zepto-sde-1-interview-experience-backend-developer-real-dsa-lld-chess-game-design","description":null,"seoDescription":" Zepto SDE-1 Backend Interview Experience covering DSA, Dynamic Programming, LLD, API Design, DB Schema, OOP & Product Company Rounds.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9884279Z","viewCount":0},{"id":213,"title":"Amazon SDE II Interview Experience (Bangalore, Selected) ~ Aug 2026","url":"amazon-sde-ii-interview-experience-bangalore-selected-aug-2026","description":null,"seoDescription":"Amazon SDE II interview experience from Bangalore covering 4 rounds, DSA, LLD, system design, Leadership Principles, coding questions and selection.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9884471Z","viewCount":0},{"id":165,"title":"Top 50+ SQL Interview Questions and Answers for Intermediate to Advanced","url":"top-sql-interview-questions-and-answers-for-intermediate-to-advanced","description":null,"seoDescription":"Top SQL Interview Questions and Answers for Intermediate to Advanced. Top SQL Interview Questions for experience. Frequently asked SQL interview questions with answers","contentType":2,"generatedOn":"2026-10-14T22:53:53.9879798Z","viewCount":0},{"id":167,"title":"Meesho SDE-1 Online Assessment Interview Experience (Remote) - Rejected","url":"meesho-sde-1-online-assessment-interview-experience-remote-rejected","description":null,"seoDescription":"Read a real Meesho SDE-1 online assessment experience with coding questions, DSA topics, solutions, difficulty level, preparation tips and interview insights.","contentType":5,"generatedOn":"2026-10-14T22:53:53.98844Z","viewCount":0},{"id":130,"title":"Rippling SDE-2 Interview Experience (4+ Years Experience) | Offer Received | Coding, LLD & System Design","url":"rippling-sde-2-interview-experience-4-years-experience-offer-received-coding-lld-system-design","description":null,"seoDescription":"Detailed Rippling SDE-2 interview experience with complete 5 rounds, coding questions, rules engine design, system design and preparation tips.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9884323Z","viewCount":0}],"latestContents":[{"id":219,"title":"6 Tools That Made My Life Easier as a Software Engineer","url":"6-tools-that-made-my-life-easier-as-a-software-engineer","description":null,"seoDescription":"The 6 developer tools I use daily as a software engineer: Git, VS Code, Docker, Postman, Chrome DevTools, and AI assistants, with real tips, mistakes, and trade","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869008Z","viewCount":0},{"id":218,"title":"When Should a Business Use Multiple AI Agents Instead of One?","url":"when-should-a-business-use-multiple-ai-agents-instead-of-one","description":null,"seoDescription":"Single agent or multi-agent AI? Learn the 4 signals that justify splitting agents by knowledge, permissions, and risk, plus routing and handoff tips.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869063Z","viewCount":0},{"id":216,"title":"AI in Clinical Trials Market Estimated to Experience a Hike in Growth by 2035","url":"ai-in-clinical-trials-market-estimated-to-experience-a-hike-in-growth-by-2035","description":null,"seoDescription":"The exclusive information about market dynamics serves as a valuable guide to predict economic scenarios and initiatives taken to enhance future growth. Our mar","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869078Z","viewCount":0},{"id":217,"title":"AI in Clinical Trials Market Estimated to Experience a Hike in Growth by 2035","url":"ai-in-clinical-trials-market-estimated-to-experience-a-hike-in-growth-by-2035","description":null,"seoDescription":"The exclusive information about market dynamics serves as a valuable guide to predict economic scenarios and initiatives taken to enhance future growth. Our mar","contentType":5,"generatedOn":"2026-10-14T22:53:53.986909Z","viewCount":0},{"id":215,"title":"What Happens When an AI Agent Doesn't Know the Answer?","url":"what-happens-when-an-ai-agent-doesnt-know-the-answer","description":null,"seoDescription":"Most AI agents fail quietly. They guess instead of saying \"I don't know.\" Here's how to design better fallback and human-handoff behavior.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869101Z","viewCount":0},{"id":214,"title":"Greedy Algorithms Explained: How They Work, When They Fail and How to Use Them","url":"greedy-algorithms-explained-how-they-work-when-they-fail-and-how-to-use-them","description":null,"seoDescription":"Learn greedy algorithms step by step with C# code Dijkstra, Huffman coding, knapsack and MSTs plus when greedy fails and how to prove it's correct","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869118Z","viewCount":0},{"id":213,"title":"Amazon SDE II Interview Experience (Bangalore, Selected) ~ Aug 2026","url":"amazon-sde-ii-interview-experience-bangalore-selected-aug-2026","description":null,"seoDescription":"Amazon SDE II interview experience from Bangalore covering 4 rounds, DSA, LLD, system design, Leadership Principles, coding questions and selection.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869131Z","viewCount":0},{"id":212,"title":"How to Get 10x Better AI Answers Without Writing Better Prompts : 10 Proven Techniques","url":"how-to-get-10x-better-ai-answers-without-writing-better-prompts-10-proven-techniques","description":null,"seoDescription":"Get better AI answers without complex prompts. Learn 10 practical techniques using context, examples, tools, feedback, and verification.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869173Z","viewCount":0},{"id":211,"title":"I Interviewed for a Microsoft SDE I Role. Here's Everything That Happened.","url":"i-interviewed-for-a-microsoft-sde-i-role-heres-everything-that-happened","description":null,"seoDescription":"My real Microsoft SDE I interview experience, all 4 rounds, the exact DSA problems with fully tested solutions, the WhatsApp system design round","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869185Z","viewCount":0},{"id":140,"title":"PolicyBazaar Software Development Engineer (SDE) Interview Experience | DSA, Core CS & System Design","url":"policybazaar-software-development-engineer-sde-interview-experience-dsa-core-cs-system-design","description":null,"seoDescription":"Detailed PolicyBazaar SDE interview experience covering 3 rounds: DSA coding, core CS assessment and system design with key learnings and insights.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9869199Z","viewCount":0}],"relatedContents":[{"id":207,"title":"How to Find the Right View of a Binary Tree","url":"right-view-of-a-binary-tree","description":null,"seoDescription":"Learn how to find the right view of a binary tree using DFS and BFS, with examples, code, complexity analysis and coding interview tips.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9956136Z","viewCount":0},{"id":205,"title":"Top View of a Binary Tree Using BFS and DFS | Complete Guide","url":"top-view-of-a-binary-tree","description":null,"seoDescription":"Learn how to find the top view of a binary tree using DFS and BFS with step-by-step explanations, examples, code, complexity analysis and interview insights.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9956209Z","viewCount":0},{"id":201,"title":"Bottom View of a Binary Tree: DFS vs BFS Approach","url":"bottom-view-of-a-binary-tree-dfs-vs-bfs-approach","description":null,"seoDescription":"Learn to find the bottom view of a binary tree using horizontal distance. Compares a buggy DFS attempt, a fixed DFS and the optimal BFS solution in Java.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9956224Z","viewCount":0},{"id":200,"title":" Longest Playlist With No Repeated Songs : Brute Force to Optimal","url":"longest-playlist-with-no-repeated-songs-brute-force-to-optimal","description":null,"seoDescription":"Find the longest playlist with no repeated songs using brute force, HashSet, and HashMap sliding window techniques, with Java code and dry runs.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9957043Z","viewCount":0},{"id":90,"title":"Contain Virus : Deep, Intuitive & Fully Explained Guide","url":"contain-virus-deep-intuitive-fully-explained-guide","description":null,"seoDescription":"Contain Virus problem explained with DFS + greedy approach, step-by-step simulation, examples and optimized solutions for coding interviews.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9957237Z","viewCount":0},{"id":37,"title":"Find the repeating and missing numbers","url":"find-the-repeating-and-missing-numbers","description":null,"seoDescription":"Find the repeating and missing numbers in an array from 1..n using brute force, hashmap, math and XOR, step-by-step explained with real-world use cases.","contentType":5,"generatedOn":"2026-10-14T22:53:53.9957297Z","viewCount":0},{"id":27,"title":"4 Sum | Find Quads that add up to a target value","url":"4-sum-find-quads-that-add-up-to-a-target-value","description":null,"seoDescription":"","contentType":5,"generatedOn":"2026-10-14T22:53:53.9957309Z","viewCount":0},{"id":26,"title":"Top 50 Most Frequently Asked String Coding Problems (Interview Preparation )","url":"top-50-most-frequently-asked-string-coding-problems-interview-preparation","description":null,"seoDescription":"","contentType":5,"generatedOn":"2026-10-14T22:53:53.9957321Z","viewCount":0},{"id":25,"title":"Intersection of Two Sorted Arrays","url":"intersection-of-two-sorted-arrays","description":null,"seoDescription":"","contentType":5,"generatedOn":"2026-10-14T22:53:53.9957336Z","viewCount":0}]}}},"source":{"isMobile":false}}; window.__CLIENT_RENDER__ = false;