Problems > Balanced Prefix > Editorial

Balanced Prefix — Solution & Editorial

Back to the Problem

Running balance (+1 for 1, −1 for 0); remember the last position where it returns to zero.

Complexity: O(|S|)