Interview Preparation
Question to ask\nsize of prime vector range\nrange of n\n\n# Intuition\ndp\n\n# Approach\nugly number just have k pointers\n\n# Complexity\n- Time complexity:\n
# Question to ask\nsize of prime vector range\nrange of n\n\n# Intuition\ndp\n\n# Approach\nugly number just have k pointers\n\n# Complexity\n- Time complexity:\n$$O(kn)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n        int k=primes.size();\n        vector<long long int> idx(k, 0), ugly(n, INT_MAX);\n        ugly[0] = 1;\n        for(int i=1; i<n; i++) {\n            for(int j=0; j<k; j++) {\n                ugly[i] = min(ugly[i], ugly[idx[j]]*primes[j]);\n            }\n            for(int j=0; j<k; j++) {\n                idx[j] += ugly[i]==(ugly[idx[j]]*primes[j]);\n            }\n        }\n        return ugly[n-1];\n    }\n};\n```
['C++']