The Infinite String
Submissions: 728   Accuracy:

18.37%

  Difficulty: Medium   Marks: 4

Consider a string A = "12345".  An infinite string s is built by performing infinite steps on A recursively. In ith step, A is concatenated with ‘$’ i times followed by reverse of A.
A=A|$...$|reverse(A), where | denotes concatenation.
Input :

First line contains an integer Q, the number of queries. Q line follows. Each line contains an integer POS i.e. the position for query.

Output:

For each query print the character in the infinite string at position POS in separate lines.

Constraints:
1<=Q<=10^5
1<=POS<=10^12

Examples:
Input:

2
3
10

Output:

3
2

** For More Input/Output Examples Use 'Expected Output' option **

Author: ShivamKD


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.