BFS(Level Order Traversal) , C++ ✅✅
Approach\n Describe your approach to solving the problem. \nUse BFS (Level Order Traversal Format) to assign values to the nodes and store them in an unordered 
# Approach\n<!-- Describe your approach to solving the problem. -->\nUse **BFS (Level Order Traversal Format)** to assign values to the nodes and store them in an **unordered map** to return the answer in **O(1) time** in the **find() function**.\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass FindElements {\npublic:\n    unordered_map<int,bool> mp;\n    FindElements(TreeNode* root) {\n        queue<pair<TreeNode*,int>> q;\n        q.push({root,0});\n        while(!q.empty())\n        {\n            int n = q.size(),f = 1;\n            for(int i = 0;i<n;i++)\n            {\n              TreeNode*  node = q.front().first;\n              int val = q.front().second;\n              q.pop();\n              if(node) mp[val] = true;\n             if(node)\n             {\n                q.push({node->left,2*val+1});\n                q.push({node->right,2*val+2});\n                f = 0;\n             }\n             else\n             {\n                q.push({NULL,2*val+1});\n                q.push({NULL,2*val+2});\n              }\n            }\n            if(f) break;\n        }  \n    }\n    bool find(int t) {\n         return mp[t]==true;\n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/64c6c860-2b36-4c39-bf33-7b4a44813c67_1689243388.5248017.jpeg)\n
['Tree', 'Breadth-First Search', 'C++']