Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Super Ugly Number



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Super Ugly Number Problem

Super Ugly Number

Problem Statement

Design a function to determine the nth super ugly number.

Super ugly numbers are positive integers whose prime factors are all contained in the given list of prime numbers factors of length m.

Examples

Example 1:
Input: position = 10, factors = [3,5,7]
Output: 35
Explanation: The sequence of super ugly numbers for the primes [3,5,7] starts as:
[1,3,5,7,9,15,21,25,27,35] and the 10th number is 35.

Example 2:
Input: position = 8, factors = [2,11]
Output: 44
Explanation: The super ugly numbers sequence for primes [2,11] is:
[1,2,4,8,11,16,22,44] and the 8th number is 44.

Constraints

  • 1 ≤ m ≤ 80
  • 1 ≤ n ≤ 5×105
  • All elements in factors are prime numbers less than 1200
  • The nth super ugly number will fit in a 32-bit signed integer