C++: Best TC O(nlogk) Solution: Priority Queue
class Solution {\npublic:\n    vector ans;\n\n    struct comparator { \n        bool operator()(pair> &p1, pair> & p2)  { \n            return p1.first > p2.fir
class Solution {\npublic:\n    vector<int> ans;\n\n    struct comparator { \n        bool operator()(pair<int, pair<int, int>> &p1, pair<int, pair<int, int>> & p2)  { \n            return p1.first > p2.first;\n        } \n    }; \n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n        priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, comparator> pq;\n        \n        for(auto i: primes) {\n            pq.push(make_pair(i, make_pair(i, 0)));\n        }\n        \n        int prev(1);\n        pair<int, pair<int, int>> curr;\n        ans.push_back(1);\n        while(ans.size() != n) {\n            curr = pq.top();\n            pq.pop();\n            if(curr.first != prev) {\n                prev = curr.first;\n                ans.push_back(curr.first);\n            }\n            pq.push(make_pair(curr.second.first * ans[curr.second.second + 1] ,make_pair(curr.second.first, curr.second.second+1)));\n        }\n        return prev;\n    }\n};
[]