C++ Accepted Solution 2 method || O(nk) and O(nlog(k))
class Solution {\npublic:\n\n    //1. without priority queue by moving pointer. time complexity O(nk)\n\tint nthSuperUglyNumber(int n, vector& primes) {\n      
class Solution {\npublic:\n\n    //1. without priority queue by moving pointer. time complexity O(nk)\n\tint nthSuperUglyNumber(int n, vector<int>& primes) {\n        int dp[n+1]; int k=primes.size();\n        memset(dp,0,sizeof(dp));\n        dp[0]=1;\n        int pointer[k];\n        memset(pointer,0,sizeof(pointer));\n        for(int i=1; i<n; i++){\n            int mn=INT_MAX;\n            for(int j=0; j<k; j++){\n                mn=min(primes[j]*dp[pointer[j]],mn);\n            }\n            dp[i]=mn;\n            for(int j=0; j<k; j++){\n                if(primes[j]*dp[pointer[j]]==mn){\n                    pointer[j]++;\n                }\n            }\n        }\n        return dp[n-1];\n    }\n};\n\n\nclass Solution {\npublic:\n\n    //2. using priority queue. time complexity O(nlogk)\n\tstruct node{\n        long long prime,pointer,val;\n        node(long long p,long long po,long long v){\n            prime=p;\n            pointer=po;\n            val=v;\n        }\n    };\n    struct compare{\n        bool operator()(const node &a,const node &b){\n            return a.val>b.val;\n        }\n    };\n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n        long long dp[n+1]; long long k=primes.size();\n        memset(dp,0,sizeof(dp));\n        dp[1]=1;\n        priority_queue<node,vector<node>,compare> pq;\n        for(long long i=0; i<k; i++){\n            pq.push(node(primes[i],1,primes[i]));\n        }\n        for(long long i=2; i<=n;){\n            node mn=pq.top(); pq.pop();\n            if(dp[i-1]!=mn.val){\n                dp[i]=mn.val; i++;\n            }\n            node p=node(mn.prime,1+mn.pointer,mn.prime*dp[mn.pointer+1]);\n            pq.push(p);\n        }\n        return dp[n];\n    }\n};
[]