Challenge - 5 Problems
Left Side View Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Left Side View for a Simple Binary Tree
What is the output of the left side view function when run on the following binary tree?
DSA Go
type TreeNode struct { Val int Left *TreeNode Right *TreeNode } func leftSideView(root *TreeNode) []int { if root == nil { return []int{} } var result []int queue := []*TreeNode{root} for len(queue) > 0 { levelSize := len(queue) for i := 0; i < levelSize; i++ { node := queue[0] queue = queue[1:] if i == 0 { result = append(result, node.Val) } if node.Left != nil { queue = append(queue, node.Left) } if node.Right != nil { queue = append(queue, node.Right) } } } return result } // Tree structure: // 1 // / \ // 2 3 // \ \ // 5 4 root := &TreeNode{Val: 1} root.Left = &TreeNode{Val: 2} root.Right = &TreeNode{Val: 3} root.Left.Right = &TreeNode{Val: 5} root.Right.Right = &TreeNode{Val: 4} output := leftSideView(root) fmt.Println(output)
Attempts:
2 left
💡 Hint
Remember, the left side view shows the first node visible at each level from the left side.
✗ Incorrect
At level 1, node 1 is visible. At level 2, node 2 is the leftmost. At level 3, node 5 is the leftmost visible node.
🧠 Conceptual
intermediate1:00remaining
Understanding Left Side View Node Selection
In the left side view of a binary tree, which nodes are included in the output?
Attempts:
2 left
💡 Hint
Think about what you see when looking at the tree from the left side.
✗ Incorrect
The left side view includes the first node visible at each level from the left side, which is the leftmost node at each level.
❓ Predict Output
advanced2:00remaining
Output of Left Side View for a Skewed Binary Tree
What is the output of the left side view function when run on this skewed binary tree?
DSA Go
type TreeNode struct { Val int Left *TreeNode Right *TreeNode } func leftSideView(root *TreeNode) []int { if root == nil { return []int{} } var result []int queue := []*TreeNode{root} for len(queue) > 0 { levelSize := len(queue) for i := 0; i < levelSize; i++ { node := queue[0] queue = queue[1:] if i == 0 { result = append(result, node.Val) } if node.Left != nil { queue = append(queue, node.Left) } if node.Right != nil { queue = append(queue, node.Right) } } } return result } // Tree structure: // 1 // \ // 2 // \ // 3 // \ // 4 root := &TreeNode{Val: 1} root.Right = &TreeNode{Val: 2} root.Right.Right = &TreeNode{Val: 3} root.Right.Right.Right = &TreeNode{Val: 4} output := leftSideView(root) fmt.Println(output)
Attempts:
2 left
💡 Hint
Even if nodes are only on the right, the left side view includes the first node at each level.
✗ Incorrect
At each level, the only node present is the right child, so it is also the leftmost node at that level.
🔧 Debug
advanced1:30remaining
Identify the Bug in Left Side View Implementation
What error will this code produce when trying to get the left side view of a binary tree?
DSA Go
func leftSideView(root *TreeNode) []int { if root == nil { return []int{} } var result []int queue := []*TreeNode{root} for len(queue) > 0 { levelSize := len(queue) for i := 0; i < levelSize; i++ { node := queue[0] queue = queue[1:] if i == 0 { result = append(result, node.Val) } if node.Left != nil { queue = append(queue, node.Left) } if node.Right != nil { queue = append(queue, node.Right) } } } return result }
Attempts:
2 left
💡 Hint
Check the loop condition carefully for off-by-one errors.
✗ Incorrect
The inner loop uses i <= levelSize which causes one extra iteration, leading to accessing queue[0] when queue is empty, causing runtime panic.
🚀 Application
expert1:30remaining
Number of Nodes in Left Side View of a Complete Binary Tree
Given a complete binary tree with height h (root at height 1), how many nodes will the left side view contain?
Attempts:
2 left
💡 Hint
The left side view shows one node per level.
✗ Incorrect
In a complete binary tree, the left side view includes exactly one node from each level, so the count equals the height h.