C++ ,heap , logic explained
\ttypedef pair> ppi;\n\tclass Solution {\n\tpublic:\n\t\tint nthSuperUglyNumber(int n, vector& primes) {\n\t\t\tpriority_queue,greater\>minh; // min heap of pai
\ttypedef pair<long long,pair<long long,long long>> ppi;\n\tclass Solution {\n\tpublic:\n\t\tint nthSuperUglyNumber(int n, vector<int>& primes) {\n\t\t\tpriority_queue<ppi,vector<ppi>,greater<ppi>>minh; // min heap of pairs {values, prime No, index of dp}\n\t\t\tlong long dp[n];\n\t\t\tdp[0]=1;                                         // 1 is the first ugly number\n\t\t\tfor(auto &i:primes)\n\t\t\t{\n\t\t\t\tminh.push({i,{i,0}});   // {value,{prime No,index}}\n\t\t\t}\n\t\t\tfor(int i=1;i<n;)\n\t\t\t{\n\t\t\t\tauto it = minh.top();   \n\t\t\t\tminh.pop(); \n\t\t\t\tlong long prime = it.second.first;    // current prime no. \n\t\t\t\tlong long ind = it.second.second;     // index \n\t\t\t\tlong long val = it.first;             // next minimum ugly number (prime no. * dp[ind])\n\t\t\t\tif(dp[i-1] != val)dp[i++] = val;      // to not allow repeatation of same ugly number\n\t\t\t\tind++;                                // incrementing the index \n\t\t\t\tit.second.second = ind;           \n\t\t\t\tit.first = prime*dp[ind];             // the updated value\n\t\t\t\tminh.push(it);                        // inserting in heap after updating\n\t\t\t}\n\t\t\treturn dp[n-1];                           // returning nth ugly number\n\t\t}\n\t};
['C', 'Heap (Priority Queue)', 'C++']