Geeksforgeeks

Error

Given a binary string **S** . Perform **R** iterations on string S, where in each iteration **0 becomes 01** and **1 becomes 10**. Find the **N**th character (considering **0 based indexing**) of the string after performing these R iterations. (See Examples for better understanding)

**Example 1:**

**Input**:
S = 101
R = 2
N = 3
**Output**:
1
**Explanation **:
After 1st iteration S becomes 100110.
After 2nd iteration, S = 100**1**01101001
Now, we can clearly see that the character
at 3rd index is 1, and so the output.

**Example**

**Input**:
S = 11
R = 1
N = 3
**Output**:
0
**Explanation**:
After 1st iteration S becomes 101**0**.
Now, we can clearly see that the character
at 3rd index is 0, and so the output.

You don't need to read input or print anything. Your task is to complete the function **nthCharacter()** which takes the string **S** and integers **R** and **N** as input parameters and returns the N-th character of the string after performing R operations on S.

1 ≤ String length ≤ 10

1 ≤ R ≤ 20

0 ≤ N < Length of final string

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

Find the N-th character

...