C++ Clean code Explained
sort the array and use HashMap to record each Integer, and the number of trees with that Integer as root\n(1) each integer A[i] will always have one tree with o
sort the array and use HashMap to record each Integer, and the number of trees with that Integer as root\n(1) each integer A[i] will always have one tree with only itself\n(2) if A[i] has divisor (a) in the map, and if A[i]/a also in the map then a can be the root of its left subtree, and A[i]/a can be the root of its right subtree;\nthe number of such tree is map.get(a) * map.get(A[i]/a)\n(3) sum over the map\n\n\n\n\n```\nclass Solution {\npublic:\n     int mod = pow(10,9) + 7;\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        sort(arr.begin(), arr.end());\n        unordered_map <int, long> rootWithCount;\n        rootWithCount[arr[0]] = 1;\n        for(int i = 1; i < arr.size(); i++){\n            long count = 1;\n            for(auto j : rootWithCount){\n                int rootEle = j.first;\n                if(arr[i] % rootEle == 0 && rootWithCount.find(arr[i] / rootEle) != rootWithCount.end()){\n                    count += rootWithCount[rootEle] * rootWithCount[arr[i] / rootEle];\n                    \n                }\n            }\n            rootWithCount[arr[i]] = count;\n        }\n        int noOfTrees = 0;\n        for(auto i : rootWithCount){\n            noOfTrees = (noOfTrees + i.second) % mod;\n        }\n        return noOfTrees;\n    }\n};\n```\n\nTC: O(N^2)\nSC: O(N)\n\n**IF YOU LIKE MY SOLUTION THEN JUST PLEASE PLEASE UPVOTE IT**
['Dynamic Programming', 'C', 'C++']