C++ ||  DP || Map || Easy || Sorting
\nDynamic Programming and Map Approach\nTime Complexity:- O(NN)\nSpace Complexity:- O(N)**\n\nNote:- In this Problem we need to calculate the factors of each nu
\n**Dynamic Programming and Map Approach\nTime Complexity:- O(N*N)\nSpace Complexity:- O(N)**\n\n***Note:-** In this Problem we need to calculate the factors of each numbers(which is  nothing but the leaf nodes) and checking whether its product is is equal to the values of the nodes or not. Also we need to use unordered map for storing the current values (No. of Binary trees obtained).*\n\nclass Solution {\npublic:\n    #define ll long long\n    #define mod 1000000007\n    \n    int numFactoredBinaryTrees(vector<int>& arr) {\n        \n        // Map for checking whether the factors are present or not.\n        unordered_map<ll,ll> mp;\n        \n        ll res=0;\n        \n        sort(arr.begin(),arr.end());\n        \n        for(int i=0;i<arr.size();i++){\n            \n            // Curr value should be 1 i.e. Leaf Node\n            ll curr = 1;\n            \n            for(int j=0;j<i;j++){\n                \n                if((arr[i]%arr[j])>0){\n                    continue;\n                }\n                \n                ll n1 = arr[j], n2 = arr[i]/arr[j];\n                \n                curr = (curr + (mp[n1]*mp[n2])%mod)%mod;\n            }\n            \n            //Updating the map\n            \n            mp[arr[i]] = curr;\n            \n            // Storing the number of binary trees obtained in a variable\n            res = (res+curr)%mod;\n        }\n        \n        \n        //Returning the number of binary trees we can make \n        \n        return (int)res;\n    }\n};
['Sorting', 'C++']