Java solution withough Math using Directecd Graph + DFS + Memoization. runtime: O(n^2)
Idea for this solution is to build a directed graph  where an edge i -> j means nums[i] % nums[j] == 0.\nsince the numbers in nums are unique, the built graph w
Idea for this solution is to build a directed graph  where an edge `i -> j` means `nums[i] % nums[j] == 0`.\nsince the numbers in `nums` are unique, the built graph will not have any cycle i.e we will end up with Directed Acyclic Graph.\nNow the answer is simply the nodes in longest path in this graph.\nWe cas use DFS to find this. While running the DFS we will mainting pointer to next Id which gives the maximum length.\nAfter we run the DFS, we can simply use the next pointer to build the answer list.\n\nHowever, as we are using DFS, we might calculate the length for same node again and again.\nTo prevent this we can use memoisation to keep track of maximum length we have seen from the node and return it directly without running DFS if we had calculated the length for this node earlier.\n\nTo build the graph, it will take `O(n ^2)` time.\nSince it it Acyclic graph, there will be at most `n ^ 2` edges and the  DFS will take `O(V + E) = O(n + n ^ 2) = O(n ^ 2)`\nThus over all runtime will be `O(n ^ 2)`\n\nCode:\n```\nclass Solution {\n    public List<Integer> largestDivisibleSubset(int[] nums) {\n        List<Integer>[] graph = buildGraph(nums);\n        \n        int longest = Integer.MIN_VALUE;\n        int nextId = 0;\n        \n        int[] length = new int[nums.length];\n        int[] next = new int[nums.length];\n        for(int i = 0; i < nums.length; i++) {\n            int len = runDFS(graph, length, next, nums, i);\n            if (len > longest) {\n                longest = len;\n                nextId = i;\n            }\n        }\n        \n        List<Integer> ans = new ArrayList<>();\n        while(nextId != -1) {\n            ans.add(nums[nextId]);\n            nextId = next[nextId];\n        }\n        \n        return ans;\n    }\n    \n    private int runDFS(List<Integer>[] graph, int[] length, int[] next, int[] nums, int id) {\n        if (length[id] != 0) {\n            return length[id];\n        }\n        \n        int idMaxLen = 1;\n        int nextId = -1;\n        for(int child : graph[id]) {\n            int tempLen = 1 + runDFS(graph, length, next, nums, child);\n            if (tempLen > idMaxLen) {\n                idMaxLen = tempLen;\n                nextId = child;\n            }\n        }\n        \n        length[id] = idMaxLen;\n        next[id] = nextId;\n        \n        return idMaxLen;\n    }\n    \n    private List<Integer>[] buildGraph(int[] nums) {\n        List<Integer>[] graph = new ArrayList[nums.length];\n        for(int i = 0; i < nums.length; i++) {\n            graph[i] = new ArrayList<Integer>();\n        }\n        \n        for(int i = 0; i < nums.length; i++) {\n            for(int j = i + 1; j < nums.length; j++) {\n                if (nums[i] % nums[j] == 0) {\n                    graph[i].add(j);\n                }\n                \n                if (nums[j] % nums[i] == 0) {\n                    graph[j].add(i);\n                }\n            }\n        }\n        \n        return graph;\n    }\n}\n```
['Depth-First Search', 'Graph', 'Memoization', 'Java']