Given a decimal number m, convert it into a binary string and apply n iterations, in each iteration 0 becomes “01” and 1 becomes “10”. Find ith(based indexing) index character in the string after nth iteration.
Input : m = 5, n = 2, i = 3 Output : 1 Input :m = 3, n = 3, i = 6 Output : 1
Recommended: Please solve it on “PRACTICE“first, before moving on to the solution.
1. Change a decimal number into binary and store in string s.
2. Run loop n times in each iteration. Run another loop of string
length s to convert 0 to “01” and 1 to “10” and store in another string s1.
After completion of each iteration, assign string s1 to s.
3. At last Return the value of ith index in string s.
Refer Set-2 for an optimized solution.
- Find i’th index character in a binary string obtained after n iterations | Set 2
- Find the character in first string that is present at minimum index in second string
- Find last index of a character in a string
- Find a string such that every character is lexicographically greater than its immediate next character
- Queries to find the last non-repeating character in the sub-string of a given string
- Queries to find the first non-repeating character in the sub-string of a string
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can be obtained by rotating another string d places
- Find Index of 0 to be replaced with 1 to get longest continuous sequence of 1s in a binary array | Set-2
- Find k'th character of decrypted string | Set 1
- Find k-th character of decrypted string | Set - 2
- Find one extra character in a string
- Find the first repeated character in a string
- Given a string, find its first non-repeating character
- Find the last non repeating character in string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.