@vcoderld I used 1*2 array in the heap. The array is like this: {value, its index in the primes}. :)

public int nthSuperUglyNumber(int n, int[] primes) { if (null == primes) return 0; Queue<int[]> heap = new PriorityQueue<>(primes.length, new Comparator<int[]>() { public int compare(int[] a, int[] b) { if (a[0] != b[0]) return a[0] - b[0]; return a[1] - b[1]; } }); int[] indices = new int[primes.length]; int[] ugNums = new int[n]; ugNums[0] = 1; for (int i = 0; i < primes.length; i ++) heap.offer(new int[]{primes[i], i}); for (int i = 1; i < n; i ++) { int[] temp = heap.poll(); // avoid adding duplicated values if (temp[0] != ugNums[i - 1]) ugNums[i] = temp[0]; else i --; indices[temp[1]] += 1; int tempVal = primes[temp[1]] * ugNums[indices[temp[1]]]; heap.offer(new int[]{tempVal, temp[1]}); } return ugNums[n - 1]; }Super Ugly Number