Concise java solution O(n^2) time O(n)space
// if we sort the array, every element in a divisibleSubset can be divisible by the element just before it.\n    // for any element k, its largestDivisibleSubse
    // if we sort the array, every element in a divisibleSubset can be divisible by the element just before it.\n    // for any element k, its largestDivisibleSubset that ends with k can be formed in the following way: \n    // use element k after any one of the previous elements that is divisble \n    public List<Integer> largestDivisibleSubset(int[] nums) {\n        int[] l = new int[nums.length]; // the length of largestDivisibleSubset that ends with element i\n        int[] prev = new int[nums.length]; // the previous index of element i in the largestDivisibleSubset ends with element i\n        \n        Arrays.sort(nums);\n        \n        int max = 0;\n        int index = -1;\n        for (int i = 0; i < nums.length; i++){\n            l[i] = 1;\n            prev[i] = -1;\n            for (int j = i - 1; j >= 0; j--){\n                if (nums[i] % nums[j] == 0 && l[j] + 1 > l[i]){\n                    l[i] = l[j] + 1;\n                    prev[i] = j;\n                }\n            }\n            if (l[i] > max){\n                max = l[i];\n                index = i;\n            }\n        }\n        List<Integer> res = new ArrayList<Integer>();\n        while (index != -1){\n            res.add(nums[index]);\n            index = prev[index];\n        }\n        return res;\n    }
['Dynamic Programming', 'Java']