Skip to content
Decoder

Ugly Number II

Medium

Problem

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 `n`th ugly number.

Example 1

Input
n = 1
Output
1

Example 2

Input
n = 10
Output
12

Example 3

Input
n = 11
Output
15

Constraints

  • 1 <= n <= 1690

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.