[C/C++] O(n) time recursive and iterative solutions. O(1) space for iterative.
Intuition\nThe problem becomes quite straight forward once you reverse the natural way of processing binary trees with the left branch before the right.\n\nRead
# Intuition\nThe problem becomes quite straight forward once you reverse the natural way of processing binary trees with the left branch before the right.\n\nReading left branch then right will result in reading the right most of each level _after_ the left most. The solution is then to process the right branch then process the left.\n\nAfter that all we need to do is remember the last entry read from the largest depth.\n\n# Approach\nThe recursive solution is straightforward, recursively traverse the tree keeping track of the depth. Anytime a depth that is larger or equal to the maximum depth encountered so far, just overwrite the return value.\n\nThe iterative solution is done using a modified Morris Traversal. In a Morris Traversal, the unwinding backup the tree is done by temporarily modifing one of the `NULL` branches of the each leaf to point back to the parent nodes. The process will revert the branch back to NULL as it moves back up the tree. \n\n# Complexity\n- Time complexity:\n    - $$O(n)$$ for recursive solutions\n    - $$O(n)$$ for iterative solutions\n\n- Space complexity:\n    - $$O(\\log_{2}{n})$$ for the recursive function calls\n    - $$O(1)$$ for the iterative solutions.\n\n# Recursive Code\n``` cpp []\nclass Solution {\npublic:\n  int findBottomLeftValue(TreeNode* root) {\n    int max_depth = 0;\n    int ret = 0;\n    find_bottom_left_value_helper(root, 1, max_depth, ret);\n    return ret;\n  }\n\nprivate:\n  static\n  void find_bottom_left_value_helper(TreeNode* root, int depth, int& max_depth, int& out) {\n    if (root) {\n      if (depth >= max_depth) {\n        max_depth = depth;\n        out = root->val;\n      }\n\n      find_bottom_left_value_helper(root->right, depth + 1, max_depth, out);\n      find_bottom_left_value_helper(root->left, depth + 1, max_depth, out);\n    }\n  }\n};\n```\n``` c []\nvoid find_bottom_left_value_helper(\n    struct TreeNode* root,\n    int depth,\n    int* max_depth,\n    int* out) {\n  if (root) {\n    if (depth >= *max_depth) {\n      *max_depth = depth;\n      *out = root->val;\n    }\n\n    find_bottom_left_value_helper(root->right, depth + 1, max_depth, out);\n    find_bottom_left_value_helper(root->left, depth + 1, max_depth, out);\n  }\n}\n\nint findBottomLeftValue(struct TreeNode* root) {\n  int ret = root->val;\n  int depth = 1;\n  find_bottom_left_value_helper(root, 0, &depth, &ret);\n  return ret;\n}\n```\n# Iterative Code\n``` cpp []\nint findBottomLeftValue(TreeNode* root) {\n  int ret = root->val;\n  int depth = 0;\n  int max_depth = 1;\n  while (root) {\n    if (root->right) {\n      int depth_diff = 1;\n      struct TreeNode* pre = root->right;\n      while (pre->left && pre->left != root) {\n        pre = pre->left;\n        ++depth_diff;\n      }\n\n      if (!pre->left) {\n        // First time at root, save link for later\n        pre->left = root;\n        root = root->right;\n        ++depth;\n      } else {\n        // Second time at root, use it now and remove link\n        pre->left = NULL;\n        // Reduce the depth to that of the root\n        depth -= depth_diff;\n        if (depth >= max_depth) {\n          max_depth = depth;\n          ret = root->val;\n        }\n        root = root->left;\n      }\n    } else {\n      // No right branch, just move down the left\n      if (++depth >= max_depth) {\n        max_depth = depth;\n        ret = root->val;\n      }\n      root = root->left;\n    }\n  }\n  return ret;      \n}\n```\n``` c []\nint findBottomLeftValue(struct TreeNode* root) {\n  int ret = root->val;\n  int depth = 0;\n  int max_depth = 1;\n  while (root) {\n    if (root->right) {\n      int depth_diff = 1;\n      struct TreeNode* pre = root->right;\n      while (pre->left && pre->left != root) {\n        pre = pre->left;\n        ++depth_diff;\n      }\n\n      if (!pre->left) {\n        /* First time at root, save link for later */\n        pre->left = root;\n        root = root->right;\n        ++depth;\n      } else {\n        /* Second time at root, use it now and remove link */\n        pre->left = NULL;\n        /* Reduce the depth to that of the root */\n        depth -= depth_diff;\n        if (depth >= max_depth) {\n          max_depth = depth;\n          ret = root->val;\n        }\n        root = root->left;\n      }\n    } else {\n      /* No right branch, just move down the left */\n      if (++depth >= max_depth) {\n        max_depth = depth;\n        ret = root->val;\n      }\n      root = root->left;\n    }\n  }\n  return ret;\n}\n```
['C', 'C++']