Balanced Prefix — Solution & Editorial
Running balance (+1 for 1, −1 for 0); remember the last position where it returns to zero.
Complexity: O(|S|)
Running balance (+1 for 1, −1 for 0); remember the last position where it returns to zero.
Complexity: O(|S|)