Mark As Completed Discussion

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.

Description

In this example, the bottom left leaf is 3:

JAVASCRIPT
1/*
2    4
3   / \
4  3   5
5*/

Assuming the standard node definition of:

JAVASCRIPT
1function Node(val) {
2  this.val = val;
3  this.left = this.right = null;
4}

It would be called as such:

JAVASCRIPT
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.

JAVASCRIPT
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 and 1000000000
  • 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?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's a video of us explaining the solution.

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?