Loading...
Loading...
Loading...
A list holds only 0 and 1 (for example failed and passed checks). Find the length of the longest block of consecutive items with equally many 0s and 1s. Print 0 if there is none.
Example
Input
7 0 1 0 0 1 1 0
Output
6
The first six items have three 0s and three 1s.
Try the problem first. Open one hint at a time.
Score a 1 as +1 and a 0 as -1. A balanced block has sum 0.
Remember the first index of each running balance. A repeat of a balance marks a balanced block.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor