```python
def find_length(string, n):
    if n == 0:
        return 0

    # This problem is equivalent to finding the maximum subarray sum
    # in an array where '0' is replaced by 1 and '1' is replaced by -1.
    # We use Kadane's algorithm to solve this in O(n) time.

    # Initialize with the value of the first character.
    first_val = 1 if string[0] == '0' else -1
    current_max = first_val
    max_so_far = first_val

    # Iterate from the second character.
    for i in range(1, n):
        val = 1 if string[i] == '0' else -1
        
        # The maximum sum ending at the current position is either the
        # current element itself or the current element added to the
        # maximum sum ending at the previous position.
        current_max = max(val, current_max + val)
        
        # Update the overall maximum sum found so far.
        max_so_far = max(max_so_far, current_max)

    return max_so_far
```