If all decimal numbers are concatenated in a string then we will get a string which looks like string P as shown below. We need to tell Nth character of this string.
P = “12345678910111213141516171819202122232425262728293031….”
Example 1:
Input: N = 10
Output: 1
Explaination: From the given portion of the 
string you can see that the 10th character is 
'1'.
Example 1:
Input: N = 11
Output: 10
Explaination: From the given portion of the 
string yuou can see that the 11th character is 
'0'.
Your Task:
You do not need to read input or print anything. Your task is to complete the function NthCharacter() which takes N as input parameter and returns the Nth character of the string P.
Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def NthCharacter(self, N):

        # code here

Solutions:
class Solution:

	def NthCharacter(self, N):
		s = ''
		for i in range(1, N + 1):
			s += str(i)
		return s[N - 1]


class Solution:

	def NthCharacter(self, N):
		p = ''
		for i in range(1, N + 1):
			p = p + str(i)
			if len(p) >= N:
				return p[N - 1]


class Solution:

	def NthCharacter(self, N):
		p = ''
		for i in range(1, N + 1):
			p = p + str(i)
			if len(p) >= N:
				return p[N - 1]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.NthCharacter(N))


class Solution:

	def givechar(self):
		start = 1
		while True:
			s = str(start)
			for i in s:
				yield i
			start += 1

	def NthCharacter(self, N):
		x = iter(self.givechar())
		for i in range(N - 1):
			next(x)
		return next(x)