C++ Crystal Clear Explanation
```\nclass Solution {\npublic:\n    vector largestDivisibleSubset(vector& A) {\n      int n = A.size();\n      \n      if(n == 0)\n          return {};\n       
```\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& A) {\n      int n = A.size();\n      \n      if(n == 0)\n          return {};\n        \n      //1. Sort A,\n      //   so that we have to only check A[j]%A[i] and not A[i]%A[j], i < j\n      \n      sort(A.begin(), A.end());\n        \n      //2. Create a vector, dp,\n      //    where dp[i] : longest subset, satisfying the required conditions and ending at index i\n      //initial length of any subset is 1  \n      vector<int> dp(n, 1);\n      \n      //3. Also create a vector, prev_index,\n      //   because if longest subset ends at some index \'t\'\n      //   we also want the indices of previously included elements in this subset, to form the subset\n      vector<int> previous_index(n, -1);\n       \n      int max_ind = 0; //this keeps track of the index at which the longest subset ends\n        \n      //4. logic :\n      //      for j<i<n,\n      //      if A[i]%A[j] = 0, then,\n      //       we can add A[i] to subset having last element as A[j], if and only if,\n      //       length of subset ending at A[j] after adding A[i] becomes more than length of subset of which A[i] is already a part\n      //       in other words, if dp[i] < dp[j] + 1   => dp[i] = dp[j]+1  \n      // also in the process we keep track of previous indices of i, and also the max_ind  \n      \n       for(int i=1; i<n; i++) {\n           for(int j=0; j<i; j++) {\n               if(A[i]%A[j]==0 and dp[i] < dp[j] + 1) {\n                   dp[i] = dp[j]+1;\n                   previous_index[i] = j;\n               }\n           }\n           if(dp[i] > dp[max_ind]) {\n               max_ind = i;\n           }\n       }\n        \n      //5. Now we just use max_ind and previous_index to form the final subset  \n        \n      vector<int> answer;\n      int t = max_ind;  \n      while(t >= 0) {\n          answer.push_back(A[t]);\n          t = previous_index[t];\n      }\n       \n      return answer;  \n    }\n};\n
[]