class Solution { public: vector<int> largestDivisibleSubset(vector<int>& nums) { int p[1001],q[1001]; memset(q,0,sizeof(q)); sort(nums.begin(),nums.end()); int i,j; for(i=0;i<1001;i++){ p[i]=1; } p[0]=1; q[0]=nums[0]; vector<int> l; l.push_back(nums[0]); vector<vector<int>> a; a.push_back(l); int maxx=0; int maxpos=0; for(i=1;i<nums.size();i++){ l.clear(); for(j=0;j<i;j++){ if(nums[i]%nums[j]==0){ if(p[i]<p[j]+1){ p[i]=p[j]+1; l=a[j]; } //l=a[j]; if(p[i]>maxx){ maxx=p[i]; maxpos=i; } } } cout<<p[i]<<" "; l.push_back(nums[i]); a.push_back(l); } return a[maxpos]; } };