DP || beats 87% || with explanation || java
/this question is same as ugly number 2 the only diffrence is we are given an array of\nn length instead of calcultaing prime factor of 2 , 3 , 5  and giving th
/this question is same as ugly number 2 the only diffrence is we are given an array of\nn length instead of calcultaing prime factor of 2 , 3 , 5  and giving the nth ugly number in output.\nThe output is same in both cases to give nth integer\nSo we apply the same trick as applied in ugly number 2 we use pointers as used in last question\nbut it will be hectic  task  to assign a diffrent pointer to each number given in array.\nso what we will do is that we\'ll create an array of length n and fill it with 1 initially\n(as all the pointer are pointing to 1 initially ) and we use them to store  the \ncurrent position at which pointer is pointing. and then update the pointer we recently used. \n THATS\'all.\n** Strongly recommend you to do ugly number 2 (leetcode 264) first for better understanding \nof this question.**\n**Discuss link for previos question https://leetcode.com/problems/ugly-number-ii/discuss/1682470/java-oror-with-comments**\n*/\n\n\n```\nclass Solution {\n\tpublic int nthSuperUglyNumber(int n, int[] primes) {\n\t\t\n         int pointers[] = new int[primes.length];\n\n            Arrays.fill(pointers, 1);\n\n            int dp[] = new int[n + 1];\n\n            dp[1] = 1;\n            for (int i = 2; i <= n; i++) {\n                  int min = Integer.MAX_VALUE;\n\t\t\t\t  //calculating result.\n                  for (int j = 0; j < primes.length; j++) {\n                        min = Math.min(min, primes[j] * dp[pointers[j]]);\n                  }\n                  dp[i] = min;\n\t\t\t\t  //updating pointer\n                  for (int j = 0; j < primes.length; j++) {\n                        if (primes[j] * dp[pointers[j]] == min) {\n                              pointers[j]++;\n                        }\n                  }\n            }\n\n            return dp[n];\n\t}\n}\n```
['Dynamic Programming', 'Java']