DP || Solution Buildup || Java
IntuitionCode
# Intuition
    Since we need subset, sorting wont affect out answer

    if we can find any subsequence
        p0, p1, p2, p3..... pk
        p1 % p0 == 0
        p2 % p1 == 0

        This satisfies our condition

    For each index i
        we see on its left side, if there is any number which divides nums[i]
            and what was the best length of series that ended that point
                we will extend that length

    Since we need the exact subarray
    we have to check at what position the best length series is ending
    and then traverse from back and build up the solution

# Code
```java []
class Solution {
    public List<Integer> largestDivisibleSubset(int[] nums) {
        int n = nums.length;

        Arrays.sort(nums);
        int[] dp = new int[n];
        Arrays.fill(dp, 1);
        int[] par = new int[n];
        Arrays.fill(par, -1);

        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] % nums[j] == 0 && 1 + dp[j] > dp[i]) {
                    dp[i] = 1 + dp[j];
                    par[i] = j;
                }
            }
        }

        // find the starting point
        int startIndex = 0;
        for (int i = 1; i < n; i++) {
            if (dp[i] > dp[startIndex])
                startIndex = i;
        }

        List<Integer> ans = new ArrayList<>();
        while (startIndex != -1) {
            ans.add(nums[startIndex]);
            startIndex = par[startIndex];
        }

        Collections.reverse(ans);

        return ans;
    }
}

```
['Java']