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

    # This problem can be solved by converting it to the maximum subarray sum problem.
    # We treat '0' as a value of 1 and '1' as a value of -1.
    # The difference (number of 0s - number of 1s) in a substring
    # corresponds to the sum of the values in the corresponding subarray.
    # We use Kadane's algorithm to find this maximum sum efficiently.

    # Initialize using the value of the first character. This correctly handles
    # cases where the maximum difference is negative (e.g., a string of all '1's).
    if string[0] == '0':
        first_value = 1
    else:
        first_value = -1
    
    current_max_diff = first_value
    global_max_diff = first_value

    # Iterate through the rest of the string to find the maximum subarray sum.
    for i in range(1, n):
        if string[i] == '0':
            value = 1
        else:
            value = -1
        
        # The maximum difference ending at the current position is either
        # the value of the current character itself or the value plus
        # the maximum difference ending at the previous position.
        current_max_diff = max(value, current_max_diff + value)
        
        # Update the overall maximum difference found so far.
        global_max_diff = max(global_max_diff, current_max_diff)
            
    return global_max_diff
```