Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a positive integer N. You have to find **N ^{th}** natural number after removing all the numbers containing digit

**Example 1:**

Input:N = 8Output:8Explanation:After removing natural numbers which contains digit 9, first 8 numbers are 1,2,3,4,5,6,7,8 and 8^{th}number is 8.

**Example 2:**

Input:N = 9Output:10Explanation:After removing natural numbers which contains digit 9, first 9 numbers are 1,2,3,4,5,6,7,8,10 and 9^{th}number is 10.

**Your Task:**

You don't need to read input or print anything. Complete the function **findNth() **which accepts an integer N as input parameter and return the N^{th} number after removing all the numbers containing digit 9.

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

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

**Constraints:**

1 ≤ N ≤ 10^{12}

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...

Nth Natural Number

...