09. Find the N-th character
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
Initialize a variable len to store the length of the input string s.
Use a loop to iterate r times for the specified number of iterations.
In each iteration :
Create a temporary string temp and copy the content of the original string s.
Use another loop to traverse each character in the original string s.
Update each character based on the following logic :
If the corresponding character in temp at position j/2 is '0', set s[j] to '0' + (j % 2).
Otherwise, set s[j] to '1' - (j % 2).
After completing all iterations, the desired character is at index n in the final string s.
Time Complexity : O(r*|s|)
, as there are two nested loops.
Auxiliary Space Complexity : O(|s|)
, as the temporary string temp is of the same length as the input string.
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.