Good afternoon! 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// 3Here'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// 5Constraints
- Nodes in the binary tree <=
100000 - The values in the nodes will be in the range
-1000000000and1000000000 - 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 console.log('PASSED: ' + 'assert.equal(bottomLeftNodeVal(tree4), 1);');var assert = require('assert');​function Node(val) { this.val = val; this.left = this.right = null;}​function bottomLeftNodeVal(root) { // Fill in this method return root;}​// const root = new Node(4);// root.left = new Node(1);// root.right = new Node(3);// root.right.left = new Node(5);// root.right.right = new Node(9);​// console.log(bottomLeftNodeVal(root));​function Node(val) { this.val = val; this.left = null; this.right = null;}​// Regular binary treesvar tree1 = new Node(4);tree1.left = new Node(1);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.

We'll now take you through what you need to know.
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.


