Heavily commented JavaScript Optimized Recursive solution
\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar largestDivisibleSubset = function(nums) {\n    /* Toughy, as there is no hints and nothing men
```\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar largestDivisibleSubset = function(nums) {\n    /* Toughy, as there is no hints and nothing mentioned about input size \n    \n    First thought is how would sort help us?\n    And should I start from the back? \n    Can I avoid doing double work?\n    \n    If 8 % 4 === 0 and 8 % 2 === 0, then I shouldn\'t be calculating 4 % 2 later on maybe\n    and if 8 4 2, should I even start a new series with 4 and 2?\n    \n    Another thought I had was to do the "include and don\'t include approach"\n    \n    Let\'s consider [2,3,4,5,6,7,8]\n    \n    I start from the beginning with: use 2 -> [2] and don\'t use 2 -> []  \n    Take those 2 arrays recursively to the next stage. \n    A) [2] can\'t use 3 so it stays the same\n    \n    b) [] can use 3 and can skip 3, so [3] and [] are now in memory\n    \n    We\'d split into many sequences, so there again we should think about: double work?\n    \n    Could we use a dp table? dp[i,sequence] = something?\n    \n    Something like that? maybe not, since we have distinct numbers. we shouldn\'t run into\n    the same sequence twice.\n    \n    # Step 1 \n    Ill try the recursive solution, see how it runs \n    before I look at other peoples solutions\n    \n    ... codeing ....\n    \n    Most of the coding was done, and it works but my console.logs show inefficiency.\n    On to \n    \n    # Step 2    \n    For example, when I\'ve discovered [ 1, 2, 4 ]\n    Who would want to be seeing where [1,4] and [2,4] go? \n    They\'ll never do better than [1,2,4]\n    \n    So im thinking of adding a map that has a count of the best length for my last number\n    so when I have {\'4\': 3} and if I come acrros something that would be \n    {\'4\': 2} I should just kill that strain.\n    \n    # Step 3\n    \n    My one cheat that I allow myself is go to discuss and search for "test case" to find\n    a nice long one. This post has one: \n    https://leetcode.com/explore/featured/card/june-leetcoding-challenge/540/week-2-june-8th-june-14th/3359/discuss/591798/Why-is-this-test-case-wrong\n    \n    That runs! Cleaned up my console logs, hit submit and it worked on the first go!\n    \n    \n    */\n    \n    // sort is necessary. tbh, I am not sure if this is more or less work than the \n    // DP-ish recursion below.\n    \n    nums.sort(function (a,b) {\n        return a-b;\n    });\n    \n    // keep track of our best array\n    var max = [];\n    // Added this for #step 2 look up efficiency\n    var map = {};\n    \n    \n    var grow = function (arr, index) {\n        let pushed = false;\n        \n       // This line gave me the insight for the optimization of step 2 \n       // console.log(arr,nums[index]);\n        \n        // Test for better lengths\n        if (arr.length > max.length) {\n            max = arr;\n        }\n        \n        // End condition\n        if (index >= nums.length) {\n            return;\n        }\n        \n        // Use the next number, if we can\n        if (arr.length === 0) {\n            grow([nums[index]], index + 1);\n        } else {\n            // The test is, does it mod zero with the last added number\n            if (nums[index] % arr[arr.length-1] === 0) {\n                \n                // #Step 2 interject: check if we want to continue this charade\n                if (map[nums[index]] && map[nums[index]] > (arr.length + 1)) {\n                    // if i\'ve already added the current number and that array\n                    // is longer than what we would be making here, just cut it off\n                    // In version 1 I did not have this check, just straight up "use"\n                } else {\n                    // classic clone and add\n                    let nextarr = [...arr];\n                    nextarr.push(nums[index]);\n                    \n                    // record length for step 2\n                    map[nums[index]] = nextarr.length;\n                    \n                    grow(nextarr, index + 1);\n                }\n                \n                \n                \n            }\n        }\n        \n        // Don\'t use the next number and see where that leads.\n        grow([...arr], index + 1);     \n    }\n    \n    grow([],0);\n    \n    return max;\n};\n```
[]