Best C++ solution in O(n^2), very easy
@amit_gupta10 thanks for the approach\n\n\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        \n        //time comp
@amit_gupta10 thanks for the approach\n\n```\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        \n        //time complexity of my approach is O(n^2)\n        int n = nums.size();\n        if(n == 0 || n == 1)    return nums;\n        \n        sort(nums.begin(),nums.end());\n        \n        vector<int> dp(n,1);\n        int maxEle = INT_MIN;\n        \n        for(int i=1;i<n;i++){\n            for(int j=i-1;j>=0;j--){\n                if(nums[i]%nums[j] == 0){\n                    int t = 1 + dp[j];\n                    if(t > dp[i])   dp[i] = t;\n                }\n            }\n            if(dp[i] > maxEle)  maxEle = dp[i];\n        }\n        \n        vector<int> v;\n        \n        for(int i=n-1;i>=0;i--){\n            if(dp[i] == maxEle){\n                v.push_back(nums[i]);\n                maxEle--;\n            }\n        }\n        \n        \n        \n        return v;\n    }\n};\n```\nplease upvote if it helps!!
[]