Most Efficient JS Solution With Explanation  💀🔫
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- O(n*m)\n- where n is n and m is length of primes array\n\n- Space complexity:\n- O(n+m)\n- where n is n and m is length of primes array\n\n# Code\n```\n/**\n * @param {number} n\n * @param {number[]} primes\n * @return {number}\n */\nvar nthSuperUglyNumber = function(n, primes) {\n    const dp = new Array(n); // Array to store super ugly numbers\n    let len = primes.length; // Number of primes given\n    let index = new Array(len).fill(0); // Array to track indices for each prime\n    dp[0] = 1; // First super ugly number is 1\n    \n    // Loop to generate super ugly numbers\n    for (let i = 1; i < n; i++) {\n        let min = Number.MAX_SAFE_INTEGER; // Initialize minimum value\n        \n        // Find the next super ugly number by multiplying each prime with its corresponding number in dp\n        for (let j = 0; j < len; j++) {\n            min = Math.min(min, primes[j] * dp[index[j]]);\n        }\n        \n        dp[i] = min; // Store the found super ugly number in dp\n        \n        // Update indices for primes whose product equals the found super ugly number\n        for (let j = 0; j < primes.length; j++) {\n            if (min == primes[j] * dp[index[j]]) {\n                index[j]++;\n            }\n        }\n    }\n    \n    return dp[n - 1]; // Return the nth super ugly number\n};\n\n\n```
['Array', 'Math', 'Dynamic Programming', 'JavaScript']