Easy || Used Map to find parents || Iterative || C++
\nclass Solution\n{\n\npublic:\n    void getParentSet(TreeNode *root, map<int, int> &mp)\n    {\n        if (root == NULL)\n            return;\n        queue<T
```\nclass Solution\n{\n\npublic:\n    void getParentSet(TreeNode *root, map<int, int> &mp)\n    {\n        if (root == NULL)\n            return;\n        queue<TreeNode *> q;\n        q.push(root);\n        TreeNode *temp;\n        while (!q.empty())\n        {\n            temp = q.front();\n            q.pop();\n            if (temp->left != NULL)\n            {\n                mp[temp->left->val] = temp->val;\n                q.push(temp->left);\n            }\n            if (temp->right != NULL)\n            {\n                mp[temp->right->val] = temp->val;\n                q.push(temp->right);\n            }\n        }\n    }\n    bool flipEquiv(TreeNode *root1, TreeNode *root2)\n    {\n        map<int, int> mp1, mp2;\n        if(root1)\n            mp1[root1->val]=-1;\n        if(root2)\n            mp2[root2->val]=-1;\n        getParentSet(root1, mp1);\n        getParentSet(root2, mp2);\n        if(mp1.size()!=mp2.size())\n            return false;\n        for (auto it : mp1)\n        {\n            if (mp2.find(it.first) != mp2.end() && mp2[it.first] == it.second)\n            {\n                continue;\n            }\n            else\n                return false;\n        }\n        return true;\n    }\n};\n```
['Iterator']