7 line consice O(kn) c++ solution
Keep k pointers and update them in each iteration.   Time complexity is O(kn).\n\n    int nthSuperUglyNumber(int n, vector& primes) {\n            vector index(
 Keep k pointers and update them in each iteration.   Time complexity is O(kn).\n\n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n            vector<int> index(primes.size(), 0), ugly(n, INT_MAX);\n            ugly[0]=1;\n            for(int i=1; i<n; i++){\n                for(int j=0; j<primes.size(); j++) ugly[i]=min(ugly[i],ugly[index[j]]*primes[j]);\n                for(int j=0; j<primes.size(); j++) index[j]+=(ugly[i]==ugly[index[j]]*primes[j]);\n            }\n            return ugly[n-1];\n    }
[]