Longest run with equal 0s and 1s
Given a list bits that contains only 0s and 1s, return the length of the longest contiguous run that holds exactly as many 0s as 1s. Return 0 if there is no such run.
bits may be empty. Aim for one pass.
Besides the tests, one large input (5,000 bits) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
longest_balanced([0,1])→2longest_balanced([0,1,0])→2longest_balanced([1,1,1,0,0,1,1,1])→4