Search⌘ K
AI Features

Solution: Super Ugly Number

Understand how to generate the nth super ugly number using a k-way merge pattern combined with a min heap. Learn to dynamically merge multiples of given prime factors while avoiding duplicates and unnecessary computation. This lesson helps you implement an efficient algorithm for this problem and analyze its time and space complexity.

Statement

Given an integer n and an array of distinct prime numbers primes, return the n-th super ugly number. A super ugly number is a positive integer whose only prime factors are from a given array primes.

The n-th super ugly number is guaranteed to fit within a 32-bit signed integer.

Constraints:

  • 11 \leq n 105\leq 10^5 ...