Power jumper program in python cognizant
View Discussion Show Improve Article Save Article View Discussion Improve Article Save Article 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. Examples: 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 Approach:
Implementation: C++
Java
Python3
C#
PHP
Javascript
Time Complexity : O(n) where n is the length of the string |