|@Rahul Jadhav 1||458|
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 Nth Ugly Number.
Input: N = 10 Output: 12 Explanation: 10th ugly number is 12.
Input: N = 4 Output: 4 Explanation: 4th ugly number is 4.
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)
1 ≤ N ≤ 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes