C++ MEMOIZATION BEST SOLUTION
Intuition\nSolution Using Memoization Using same concept as in Ugly 2\n\n# Approach\nMemoization\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexi
# Intuition\nSolution Using Memoization Using same concept as in Ugly 2\n\n# Approach\nMemoization\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    long long solve(vector<long long>& dp, int n, int i, vector<int>& primes, vector<long long>& indices) {\n        if (i == n) {\n            return dp[n - 1];\n        }\n\n        long long nextUgly = INT_MAX;\n        for (int j = 0; j < primes.size(); ++j) {\n            nextUgly = min(nextUgly, dp[indices[j]] * primes[j]);\n        }\n\n        dp[i] = nextUgly;\n\n        for (int j = 0; j < primes.size(); ++j) {\n            if (dp[indices[j]] * primes[j] == nextUgly) {\n                indices[j]++;\n            }\n        }\n\n        return solve(dp, n, i + 1, primes, indices);\n    }\n\n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n        vector<long long> dp(n, -1);\n        dp[0] = 1;\n        vector<long long> indices(primes.size(), 0);\n\n        return solve(dp, n, 1, primes, indices);\n    }\n};\n\n\n\n```
['Dynamic Programming', 'Memoization', 'C++']