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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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 the last remaining Character in the Binary String according to the given conditions
- String obtained by reversing and complementing a Binary string K times
- Find the number obtained after concatenation of binary representation of M and N
- Largest index for each distinct character in given string with frequency K
- Index of character depending on frequency count in 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
- Find Index of 0 to be replaced with 1 to get longest continuous sequence of 1s in a binary array | Set-2
- Find one extra character in a string
- Find the last non repeating character in string
- Find the Nth occurrence of a character in the given String
- Find k'th character of decrypted string | Set 1
- Find the first repeated character in a string
- Given a string, find its first non-repeating character
- Find k-th character of decrypted string | Set - 2
- How to find index of any Currency Symbols in a given 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.