X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Nth digit of pi
Hard Accuracy: 43.79% Submissions: 475 Points: 8

Calculate the Nth digit in the representation of Pi.

 

Example 1:

Input:
N = 1
Output:
3
Explanation:
Value of Pi is 3.14... 
So, the first digit is 3.

Example 2:

Input:
N = 2
Output:
1
Explanation:
Value of Pi is 3.14... 
So, the second digit is 1.

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function nthDigOfPi() which takes an Integer N as input and returns the Nth digit of Pi.

 

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

 

Constraints:
1 <= N <= 104

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Nth digit of pi

Output Window