Easy || Beiggner Friendly Approach
Intuition\nThe intuition behind this code is to find the number of factored binary trees that can be constructed from a given array of integers. \nIt uses dynam
# Intuition\nThe intuition behind this code is to find the number of factored binary trees that can be constructed from a given array of integers. \nIt uses dynamic programming to calculate the number of valid combinations using the given factors.\n\nThe code sorts the input array and initializes a map to store the count of binary trees for each element. It then iterates through the array, calculating the count of binary trees for each element by considering its factors and previously calculated counts for smaller elements. \nFinally, it returns the total count of valid binary trees modulo 1e9 + 7.\n\n# Complexity\n- Time complexity: O(n^2)\n\n- Space complexity: O(n)\n# Code\n```\nclass Solution {\npublic:\n    int mod = 1e9 + 7 ;\n    int numFactoredBinaryTrees(vector<int>& arr) \n    {\n        sort(arr.begin(),arr.end()) ;\n        int n = arr.size() ;\n        long long ans = 1 ;\n        \n        \n        unordered_map<int,long long> mapp ;\n\n        for(auto x : arr)\n           mapp[x] = 1 ;\n        \n        for(int i = 1 ; i < n ; i++)\n        {\n            long long  cnt = 0 ;\n            for(int j = 0 ; j <= i-1 ; j++)\n            {\n                    if(arr[i] % arr[j] == 0)\n                    {\n                        int right = arr[i] / arr[j] ;\n\n                        if(mapp[right] > 0)\n                            cnt = (cnt + mapp[arr[j]]*mapp[right]) % mod ;\n                    }\n            }\n            mapp[arr[i]] = mapp[arr[i]] + cnt ;\n            ans = (ans + mapp[arr[i]]) % mod ;\n        }\n\n        return ans % mod;\n\n    }\n};\n```
['Dynamic Programming', 'C++']