Good morning! Here's our prompt for today.
Assume we're using a binary tree
in writing a video game via Binary Space Partitioning. We need to identify the bottom left leaf, that is-- the leftmost value in the lowest row of the binary tree.

In this example, the bottom left leaf
is 3
:
1/*
2 4
3 / \
4 3 5
5*/
Assuming the standard node definition of:
1function Node(val) {
2 this.val = val;
3 this.left = this.right = null;
4}
It would be called as such:
1const root = new Node(4);
2root.left = new Node(3);
3root.right = new Node(5);
4
5function bottomLeftNodeVal(root) { return; };
6bottomLeftNodeVal(root);
7// 3
Here's another example. Let's assume that there's at least the root node available in all binary trees passed as parameters.
1/*
2 4
3 / \
4 1 3
5 / \
6 5 9
7*/
8
9const root = new Node(4);
10root.left = new Node(1);
11root.right = new Node(3);
12root.right.left = new Node(5);
13root.right.right = new Node(9);
14
15bottomLeftNodeVal(root);
16// 5
Constraints
- Nodes in the binary tree <=
100000
- The values in the nodes will be in the range
-1000000000
and1000000000
- Expected time complexity :
O(n)
- Expected space complexity :
O(n)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
​
def bottom_left_node(root):
# fill in
return root
​
​
# Node definition
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
​
​
# Regular binary trees
tree1 = Node(4)
tree1.left = Node(1)
tree1.right = Node(3)
​
tree2 = Node(5)
tree2.left = Node(10)
tree2.left.left = Node(17)
tree2.left.right = Node(3)
tree2.right = Node(8)
​
# Binary search trees
tree3 = Node(6)
tree3.left = Node(3)
​
tree4 = Node(5)
Tired of reading? Watch this video explanation!
To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

Here's our guided, illustrated walk-through.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.