Java Solution in 32ms O(N^2) time, O(N) space
public class Solution {\n        public int[] largestDivisibleSubset(int[] nums) {\n            if(nums.length < 2)\n                return nums;\n            e
    public class Solution {\n        public int[] largestDivisibleSubset(int[] nums) {\n            if(nums.length < 2)\n                return nums;\n            else{\n                Arrays.sort(nums);\n                int[] parent = new int[nums.length];\n                int[] count = new int[nums.length];\n                int max = 0, maxind = -1;\n                for(int i = nums.length - 1; i >= 0; i--){\n                    for(int j = i; j < nums.length; j++){\n                        if(nums[j] % nums[i] == 0 && count[i] < 1 + count[j] ){\n                            count[i] = 1 + count[j];\n                            parent[i] = j;\n                            if(count[i] > max){\n                                max = count[i];\n                                maxind = i;\n                            }\n                        }\n                    }\n                }\n                int[] res = new int[max];\n                for(int i = 0; i < max; i++){\n                    res[i] = nums[maxind];\n                    maxind = parent[maxind];\n                }\n                return res;\n            }\n        }\n    }
['Dynamic Programming']