Aasan with map aao samjau || C++, Beats 75%
Intuition and Approach\nDekho sabse phele apn ko bottom most level me jana hain and then secondly usme joh sabse left side pr ayga usko as a answer bhejna hain\
# Intuition and Approach\nDekho sabse phele apn ko bottom most level me jana hain and then secondly usme joh sabse left side pr ayga usko as a answer bhejna hain\n\nThik toh ab isko kese kre,\nAb dekho normal approach hr level ke elements ko store kr lo,\n\nkya hm vector ka use kre level store krne ke liye ->> Nahi !\nuse kro unordered map kyuki we dont know kitni levels hone wali hain\nTree :\n![image.png](https://assets.leetcode.com/users/images/c08b0816-4161-4ccd-a425-aaac394470bd_1709098450.4756334.png)\n\nStored in map look :\nLevel - Root Values at that Level\n![image.png](https://assets.leetcode.com/users/images/18f0bb56-30ed-40c5-a52a-bde964554fab_1709098417.6168091.png)\n\nAb chalo code pr agge smjhe,\n\n# Complexity\nArey, dekh, humare paas ek ped hai. Har ped ke do bacche hote hain - ek baayaan aur ek daayaan. Har bacche ke paas ek number hota hai. Toh, hume ek function banani hai jo sabse neeche wala, baayaan ke bacche ka number nikale.\n\nAb, hum kya karenge? Hum saare bacchon ke numbers ko ek map mein daal denge, jahan unke level ke hisaab se group karenge. Jaise, agar ek level pe teen bacche hain toh un teeno ke numbers ek group mein honge.\n\nPhir, hum map mein se sabse neeche wale level ka number uthayenge, aur us level ke sabse pehle bacche ka number return karenge.\n\nIss kaam ko karne mein hum sab bacchon ko ek baar hi dekhte hain, toh time complexity O(n) ho jati hai, jahan \'n\' ped ke bacchon ki sankhya hai.\nSpace Complexity bhi O(n) hogi or kya.\n\n# Code\n``` C++ []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    void solve(TreeNode *root,int lvl,unordered_map<int,vector<int>>& um){\n        //return if node is null\n        if(root == nullptr){return;}\n\n        // push root value in map , and ussi level pr krna \n        um[lvl].push_back(root->val);\n\n        // start kro traversing from left first\n        // jb we call kr rhe hain lvl ek se bdha kr bhejna or kya\n        solve(root->left,lvl+1,um);\n        solve(root->right,lvl+1,um); \n    }\n    int findBottomLeftValue(TreeNode* root) {\n        // map bnaya\n        unordered_map<int,vector<int>> um;\n        // recursion call kiya thik\n        solve(root,0,um);\n\n        // ab max depth wali level ka number find krenge\n        int maxi=0;\n        for(auto val:um){maxi=max(maxi,val.first);}\n\n        // us max depth lvl ki first value answer hoga as we are\n        // pushing leftmost value first \n        return um[maxi][0];\n    }\n};\n```\n```Java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nimport java.util.*;\n\nclass Solution {\n    public void solve(TreeNode root, int lvl, HashMap<Integer, List<Integer>> um) {\n        // Return if node is null\n        if (root == null) {\n            return;\n        }\n\n        // Push root value in map, and at the same level\n        um.computeIfAbsent(lvl, k -> new ArrayList<>()).add(root.val);\n\n        // Start traversing from the left first\n        // When calling, increment the level\n        solve(root.left, lvl + 1, um);\n        solve(root.right, lvl + 1, um);\n    }\n\n    public int findBottomLeftValue(TreeNode root) {\n        // Create a map\n        HashMap<Integer, List<Integer>> um = new HashMap<>();\n\n        // Call the recursion\n        solve(root, 0, um);\n\n        // Find the level number of the maximum depth\n        int maxi = 0;\n        for (Map.Entry<Integer, List<Integer>> entry : um.entrySet()) {\n            maxi = Math.max(maxi, entry.getKey());\n        }\n\n        // The first value of the maximum depth level is the answer\n        // as we are pushing the leftmost value first\n        return um.get(maxi).get(0);\n    }\n}\n\n```
['Math', 'Tree', 'Breadth-First Search', 'Ordered Map', 'C++']