[Java] PriorityQueue Solution with Explanation, Time: O(NlogK)
\n// PriorityQueue Solution\n// The next super ugly number can be generated from the previous ugly number * certain prime.\n// To get currently min ugly number,
```\n// PriorityQueue Solution\n// The next super ugly number can be generated from the previous ugly number * certain prime.\n// To get currently min ugly number, we can use a PriorityQueue as min heap.\n// So we need to store tuples (ugly number, index, prime) in PriorityQueue.\n// The 1st element indicates the current ugly number;\n// The 2nd element indicates the index in the uglyNums;\n// The 3rd element indicates the prime to generate current ugly number.\n// Add the peek() element to get the min ugly num and add to uglyNums array.\n// And then, use the min ugly number * its prime in the min heap to generate next ugly number.\n// Note: there might be some duplicated ugly number generated by different primes.\n// Poll all duplicated ugly number and times by their own primes then add back to the min heap.\n// Time complexity: O(NlogK), where K is the length of primes array.\n// Space complexity: O(N + K)\nclass Solution {\n    public int nthSuperUglyNumber(int n, int[] primes) {\n        if (n <= 0 || primes == null || primes.length == 0) throw new IllegalArgumentException("Invalid input");\n        if (n == 1) return 1;\n        PriorityQueue<Ugly> minHeap = new PriorityQueue<>((u1, u2) -> Integer.compare(u1.ugly, u2.ugly));\n        int[] uglyNums = new int[n];\n        uglyNums[0] = 1;\n        for (int i = 0; i < primes.length; i++) {\n            minHeap.add(new Ugly(primes[i], i + 1, primes[i]));\n        }\n        for (int i = 1; i < n; i++) {\n            uglyNums[i] = minHeap.peek().ugly;\n            while (!minHeap.isEmpty() && minHeap.peek().ugly == uglyNums[i]) {\n                Ugly ugly = minHeap.poll();\n                int nextUgly = uglyNums[ugly.index] * ugly.prime;\n                if (nextUgly > 0) {  // In case integer overflow\n                    minHeap.add(new Ugly(nextUgly, ugly.index + 1, ugly.prime));\n                }\n            }\n        }\n        return uglyNums[n-1];\n    }\n    \n    class Ugly {\n        int ugly, index, prime;\n        Ugly(int ugly, int index, int prime) {\n            this.ugly = ugly;\n            this.index = index;\n            this.prime = prime;\n        }\n    }\n}\n```
[]