C++ Solution that's Accepted
C++ solution that works with priority_queue but w/o set to record visited elements.\n\nThe tricky part is that instead of using a visited set to check number al
C++ solution that works with priority_queue but w/o set to record visited elements.\n\nThe tricky part is that instead of using a visited set to check number already visited, you just need to compare the number with the last element in the vector of ugly numbers.\n\nTime complexity: O(n logk), k is the number of element in primes\n```\nclass Solution {\npublic:\n    int nthSuperUglyNumber(int n, vector<int>& primes) {\n        int size = primes.size();\n        \n        // initialize res with first value 0 \n        vector<int> res;\n        res.push_back(1);\n        \n        if (primes.size() == 0) {\n            return -1;\n        }\n        \n        // first is value, second is index of prime, third is the current index for this prime,\n        // need to select the lowest value each time\n        auto comparator = [](tuple<long, int, int>& t1, tuple<long, int, int>& t2) {\n            return get<0>(t1) > get<0>(t2);\n        };\n        priority_queue<tuple<long, int, int>, vector<tuple<long, int, int>>, decltype(comparator)> minQueue(comparator);\n        \n        // Add all values and starting index to 0\n        for (int i = 0; i < primes.size(); i++) {\n            minQueue.push(make_tuple(primes[i], i, 1));\n        }\n        \n        while (res.size() != n) {\n            // pop min value in the minQueue and pop value in the queue\n            auto [curValue, primeIndex, curIndex] = minQueue.top();\n            minQueue.pop();\n            \n            if (curValue > res.back()) {\n                res.push_back(curValue);\n            }\n            minQueue.push(make_tuple((long) res[curIndex] * primes[primeIndex], primeIndex, curIndex + 1));\n        } \n        \n        return res[n - 1];\n    }\n};\n\n```
['C']