Given a string consisting of 1 and 0, the task is to find out the maximum power of jump required to reach the end of the string. At a time you can jump from one 1 to next 1 or from one 0 to next 0.
Note: Power of jump is defined as the distance between two consecutive 1’s or two consecutive 0’s.
Input: 10101 Output: 2 First, make a power jump of 1 to reach first 1, then a power jump of 2 to reach second 1 and then finally a power jump of 2 to reach the end of the string hence the maximum power of jump is 2. Input: 11110 Output: 5 Since to reach the end of the string, we have to make power jump of 5 to reach 0 and end of the string
- Check if the last character of given string is 1 or 0.
- If the last character is 1 then search for the first 1 in the string and continue to jump to the next 1 to reach the last of the string. Update the maximum jumps.
- Similarly, if the last character is 0 then search for the first 0 in the string and continue to jump to the next 0 to reach the last of the string. Update the maximum jumps.
- Return the maximum number of jumps taken to reach the end.
Time Compexity : O(n) where n is the length of the string
- Minimum number of given operations required to convert a string to another string
- Minimum changes required to make first string substring of second string
- Minimum moves to reach from i to j in a cyclic string
- Find time taken for signal to reach all positions in a string
- Find sub-string with given power
- Minimum number of sub-strings of a string such that all are power of 5
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Minimum rotations required to get the same string
- Minimum rotations required to get the same String | Set-2
- Minimum splits in a binary string such that every substring is a power of 4 or 6.
- Minimum changes required such that the string satisfies the given condition
- Operations required to make the string empty
- Count of lines required to write the given String
- Minimum swaps required to convert one binary string to another
- Minimum number of operations required to sum to binary string S
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.