Skip to content

Ugly Number II

MediumHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.

An ugly number is a positive integer whose only prime factors are 2, 3 and 5. By convention, 1 is the first ugly number. The sequence starts 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ... (7 and 11 are missing because they are prime, 14 because it has the factor 7).

Given n, return the nth ugly number.

n = 1   →  1
n = 10  →  12
n = 11  →  15

Constraints

  • 1 <= n <= 1690