Heavily commented Javascript bottom up DP solution
\n/**\n * @param {number} n\n * @param {number[]} primes\n * @return {number}\n */\nvar nthSuperUglyNumber = function(n, primes) {\n    // General idea is to bu
```\n/**\n * @param {number} n\n * @param {number[]} primes\n * @return {number}\n */\nvar nthSuperUglyNumber = function(n, primes) {\n    // General idea is to build up an array with super ugly numbers till we reach n-1\n    // So we will iterate multiples of [primes] and record them.\n    // Let\'s say primes is [2,3,5] -\n    // If we just store 2,3,5 - 4,6,10 - 6,9,15 etc we\'d be going out of order\n    // So we need to increase the indeces for [primes] more wisely.\n    \n    // we record our prime indeces here in an array that starts out as zeroes\n    // e.g [2,1,0] would imply that we used the first prime twice and second prime once\n    // and the 3rd prime is yet unused. For 2,3,5 that means we\'d have recorded\n    // [2,3,4] \n    \n    let indeces = [];\n    let currents = [];\n    let i, l;\n    // fill up our indeces array with zeroes to start\n    for (i = 0, l = primes.length; i < l; i++) {\n        indeces[i] = 0;\n    }\n    let out = [1]; // we will record or prime multiples here\n    \n    while (!out[n-1]) { \n        // simply calculate the next multiple of all the primes\n        for (i = 0, l = primes.length; i < l; i++) {\n            currents[i] = out[indeces[i]] * primes[i]; \n            // so in the case of 2,3,5 , currents would come out as [2,3,5] first round.\n            // Then we use 2 and increase the index of that prime. Next round it would calculate to [4,3,5], then use 3, then calculate to [4,6,5] etc\n        }\n        \n        // select the lowest one next so we stay in order\n        let next = Math.min(...currents);\n        out.push(next);\n        \n        // and for that prime we increase the index so next round we find the next multiple of that prime\n        for (i = 0, l = primes.length; i < l; i++) {\n            if (next === out[indeces[i]] * primes[i]) {\n                indeces[i] = indeces[i] + 1;\n            }\n        }\n    }\n    \n    return out[n-1];\n};\n\n```
['Dynamic Programming', 'JavaScript']