35. Goomba Jump

Time Limit: 1 seconds

Memory Limit: 128 MB

Rating: 1000

Problem Statement

You are given an array $N$ with $0$ representing open space and $1$ being a goomba. Initially you can jump over one goomba, after jumping over a goomba, your next jump can be over one additional goomba. Find out how many goombas you can jump over until there are too many. The goombas that you jump over in each jump have to be consecutive. You cannot make a jump of $3$ over $010110$, but have to make a jump of $1$ then a jump of $2$ in this case. *Note: you only get an additional goomba jump if the jump was over the maximum amount of goombas you can jump over. If the goombas are longer than your max jump none of them count. *See explanation of input 1 for more details.

Input

The first line contains string $N$, made up of characters $0$ and $1$.

Output

Output the answer described in the Problem Statement.

Sample Cases
Sample Input 1:
010110101111

Sample Output 1:
4


Sample Input 2:
0010100000

Sample Output 2:
2
Explanation

*In this explanation, 1-indexing is used. At position $2$, you jump over the first goomba. Since you are jumping over one Goomba, your max jump increases to $2$. On your next jump you can jump over a maximum of $2$ Goombas. You jump over two more Goombas, the ones on position $4$ and position $5$. This increases your max jump to $3$. Your max jump is $3$, so you are able to jump over the Goomba at position $7$. Your max jump remains at $3$. You then run into $4$ goombas in a row which you can’t jump over because your max jump is only $3$. You die and should output $4$ as you jumped over $4$ $(1 + 2 + 1)$ goombas before dying.

Sources

KL Coding Cup March 2023 > Super Mario > Problem 2

Submit | Back