PythiloEasy · 12 min · Task 47 of 100 · progress kept in this browser

Balanced binary prefix

Return the length of the longest prefix with equal counts of 0 and 1 in a binary list. The empty prefix is allowed.

balance = 0
for value in [0, 1, 1, 0]:
    balance += 1 if value else -1
    print(balance)
Your task

Return the length of the longest prefix with equal counts of 0 and 1 in a binary list. The empty prefix is allowed.