> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/trees/find-bottom-left-tree-value.md).

# Find Bottom Left Tree Value

Given a binary tree, find the leftmost value in the last row of the tree.

**Example 1:**<br>

```
Input:

    2
   / \
  1   3

Output:
1
```

**Example 2:**<br>

```
Input:

        1
       / \
      2   3
     /   / \
    4   5   6
       /
      7

Output:
7
```

**Note:** You may assume the tree (i.e., the given root node) is not **NULL**.

```java
class Solution {
    public int findBottomLeftValue(TreeNode root) {
        Queue<TreeNode> q = new LinkedList<>();
        q.add(root);
        int ans = -1;
        while (q.size() != 0) {
            int size = q.size();
            int element = 0;
            boolean firstElement = true;
            while (size-- > 0) {
                TreeNode node = q.poll();
                if (firstElement) {
                    firstElement = false;
                    element = node.val;
                }
                if (node.left != null)
                    q.add(node.left);
                if (node.right != null) 
                    q.add(node.right);
            }
            if (q.size() == 0)
                ans = element;
        }
        return ans;
    }
}
```
