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
- Check if a string can be obtained by rotating another string 2 places
- Given a string, find its first non-repeating character
- Find the last non repeating character in string
- Find k'th character of decrypted string | Set 1
- Find the first repeated character in a string
- Find k-th character of decrypted string | Set - 2
- Find one extra character in a string
- Find Index of 0 to be replaced with 1 to get longest continuous sequence of 1s in a binary array | Set-2
- Program to find the kth character after decrypting a string
- Find repeated character present first in a string
- Efficiently find first repeated character in a string without using any additional data structure in one traversal
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.
Improved By : manishshaw1