Simple Java solution using Recursion and Memoization both
\n//...APPROCH...\n\n//Lets first see the Recursive solution which will help you to understand the memoization one.\n//like the knapsack every time we had two c
```\n//...APPROCH...\n\n//Lets first see the Recursive solution which will help you to understand the memoization one.\n//like the knapsack every time we had two choices weather to take or not. but here you can compare this with LIS that is we can conclude an element in our list only if it is divisible by previous elelement.\n\n//WHY SORTING ?\n//and why i am sorting the array just to maintain the pairwise possible answer,\n\n//Recursive code\nclass Solution {\n    static List<Integer> res;\n    public List<Integer> largestDivisibleSubset(int[] nums) {\n        Arrays.sort(nums);\n        List<Integer> ans=new ArrayList<>();\n        res=new ArrayList<>();\n\n        solve(nums,0,1,ans);\n        return res;\n    }\n    static void solve(int nums[], int i, int prev,List<Integer> ans){\n        \n        if(i>=nums.length) {\n            if(ans.size()>res.size()){\n                res.clear();\n                res.addAll(ans);\n            }\n            return;\n        }\n\t\t // conisdering into our list ...\n\t\t \n        if(nums[i]%prev==0 || prev%nums[i]==0){\n            ans.add(nums[i]);\n            solve(nums,i+1,nums[i],ans);\n            ans.remove(ans.size()-1);\n        }\n\t\t//not considering into list......\n\t\t\n        solve(nums,i+1,prev,ans);\n        \n    }\n}\n```\n\n```\n// you might get confused while seeing use of dp array, just remove that dp array then it will be\n//more clear ans consize for you//\n\nclass Solution {\n    static List<Integer> res;\n    static int dp[];\n    public List<Integer> largestDivisibleSubset(int[] nums) {\n        Arrays.sort(nums);\n        dp=new int[nums.length+1];\n        List<Integer> ans=new ArrayList<>();\n        res=new ArrayList<>();\n        Arrays.fill(dp,-1);\n        solve(nums,0,1,ans);\n        return res;\n    }\n    //we have two condtions for every element weather to tkae the eleemnt or not,\n    //takini=g or adding into my list will happen only if the no. is divisible\n    \n    static void solve(int nums[], int i, int prev,List<Integer> ans){\n        \n        if(i>=nums.length) {\n            if(ans.size()>res.size()){\n                res.clear();\n                res.addAll(ans);\n            }\n            return;\n        }\n        // taking condition.....\n        \n        if(ans.size()>dp[i] && (nums[i]%prev==0 || prev%nums[i]==0)){\n            dp[i]=ans.size();\n            ans.add(nums[i]);\n            solve(nums,i+1,nums[i],ans);\n            ans.remove(ans.size()-1);\n        }\n        //not taking condition.....\n        \n        solve(nums,i+1,prev,ans);  \n    }\n}\n```\n//DO UPVOTE IF YOU GET THIS, IF YOU NOT DO PING ME!
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']