C++ | O(N) | Unordered_map Solution
Please upvote if this helped :) Cheers\n\nFirst map all arr elements to its indexes in unordered map.\nMake a temp variable to store index.\nIterate first vecto
**Please upvote if this helped :) Cheers**\n\nFirst map all arr elements to its indexes in unordered map.\nMake a temp variable to store index.\nIterate first vector of pieces, say [2, 3, 4, 5].\nuse find function find 2 in hashmap and map iterator to find index 2 is mapped to. Store that index in temp. do temp++. \nThen look for 3. if index mapped with 3 is equal to temp them continue. Otherwise return false.\n```\nclass Solution {\npublic:\n    bool canFormArray(vector<int>& arr, vector<vector<int>>& pieces) {\n        \n        // TC : O(N) + O(N)   making hasmap + iterating pieces\n        // SC : O(N) hashmap\n        \n        unordered_map <int, int> mp;\n        \n        for(int i = 0; i<arr.size(); i++){\n            \n            mp[arr[i]] = i;\n            \n        }\n        \n        int temp = -1;\n        unordered_map <int, int> :: iterator map_it;\n        for(auto it : pieces){\n            \n            for(auto pr : it){\n                \n                if(mp.find(pr) != mp.end()){\n                    if(temp == -1){\n                    map_it = mp.find(pr);\n                    temp = map_it -> second;   \n                    }\n                    map_it = mp.find(pr);\n                    if(temp++ != map_it -> second) return false;                    \n                }\n                else return false;\n            }\n            temp = -1;\n        }\n        return true;\n    }\n};\n```
['C', 'C++']