1127. Ugly Number II — Nth Ugly Number

EasyDynamic Programming1D DP

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given n, return the nth ugly number (the sequence starts with 1). The input is JSON {n}.

Input: JSON {n}.

Output: Integer — the nth ugly number.

Examples

Example 1
Input: {"n":10}
Output: 12
Explanation: 1,2,3,4,5,6,8,9,10,12.
Example 2
Input: {"n":1}
Output: 1
Explanation: 1 is ugly by convention.
Example 3
Input: {"n":11}
Output: 15
Explanation: The 11th ugly number.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →