Find Bottom Left Tree Value

Advanced

In this coding challenge, we're going to explore the world of binary trees! Imagine you are in a magical forest, and you have a tree. Your task is to find the bottom left value of this mystical binary tree. The bottom left value is the leftmost value in the last row of the tree.

A binary tree is a structure where each node can have up to two children: a left child and a right child. Each node has a value. The root is the topmost node.

Let's imagine you have a binary tree like this:

     1
   /   \
  2     3
 / \   /
4   5 6

The bottom left value is 4 because it is the leftmost value in the lowest level of the tree.

Your task is to write a function find_bottom_left_value that takes the root of a binary tree and returns the bottom left value.

Here's an example:

# Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.right.left = TreeNode(6) print(find_bottom_left_value(root)) # should return 4

Have fun solving the puzzle and may the binary tree spirits guide you!

Geek
Inputs

Arg 1:

{"val":1,"left":{"val":2,"left":{"val":4,"left":null,"right":null},"right":{"val":5,"left":null,"right":null}},"right":{"val":3,"left":{"val":6,"left":null,"right":null},"right":null}}
Expected Output
4
Actual Output
Find Bottom Left Tree Value [advanced] | Coding for Kids