Day 26 || elegant solution || hindi explaination
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\njo number bada h usse bade number uske niche nahi aa sakte\nto hum array 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\njo number bada h usse bade number uske niche nahi aa sakte\nto hum array ko sort kar lege aur end se traverse karege\nab jo last number h vo khud bhi nhi ho sakta kyunki 1 present nhi hai\nte constraints mei likha hai\nto hum 0 se us number ke index tak traverse karege (par us number ko nhi lenge matlab agar uska index n h to hum 0 se n-1 tak traverse karege bith inclusive)\nagar mujhe numbers mil jaate h to recursively ans nikal lege\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    unordered_map<int,long long> answer;\n    //unordered_map<int,bool> present;\n    unordered_map<int,int> indexMap;\n    long long mod = 1e9+7;\n    vector<int> nums;\n\n    long long solve(int index)\n    {\n        int num = nums[index];\n\n        if(answer[num]!=0)\n        {\n            return answer[num];\n        }\n\n        long long tempans = 0;\n        for(int i=0;i<index;i++)\n        {\n            if(num%nums[i]==0 && indexMap[num/nums[i]])\n            {\n                int left = nums[i];\n                int right = num/nums[i];\n\n                tempans = tempans+(solve(indexMap[left]-1)*solve(indexMap[right]-1));\n            }\n        }\n\n        answer[num] = tempans+1;\n        return answer[num]; \n    }\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        nums = arr;\n        sort(nums.begin(),nums.end());\n        for(int i=0;i<nums.size();i++)\n        {\n            indexMap[nums[i]] = i+1;\n        }\n        \n        long long finalans = 0;\n        for(int i=nums.size()-1;i>=0;i--)\n        {\n            if(answer[nums[i]]==0)\n            {\n                long long ans = solve(i);\n                finalans = (finalans+ans)%mod;\n            }\n            else\n            {\n                finalans = (finalans+answer[nums[i]])%mod;\n            }\n        }\n        return (int)finalans;\n    }\n};\n```
['C++']