Search⌘ K
AI Features

Solution: Super Ugly Number

Explore how to use a k-way merge approach combined with a min heap to efficiently find the n-th super ugly number. Learn this technique to dynamically generate numbers with given prime factors, avoid redundancy, and apply priority queues for ordered data processing.

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

  • 11 \leq primes.length ...