Geeksforgeeks

Error

Ugly numbers are numbers whose **only prime factors are 2, 3 or 5**. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … shows the first 11 ugly numbers. By convention, 1 is included. Write a program to find **N ^{th}** Ugly Number.

**Example 1:**

**Input:
**N = 10
**Output: **12
**Explanation:** 10_{th} ugly number is 12.

**Example 2:**

**Input:
**N = 4
**Output:** 4
**Explanation: **4_{th} ugly number is 4.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **getNthUglyNo()** which takes an integer **n**** **as parameters and returns an integer denoting the answer.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N ≤ 10^{4}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Ugly Numbers

...