You are given a binary string that contains only 0's and 1's. Your task is to find the length of the substring where (no of 0's - no of 1's) is maximum.
Example:
1000100110101
Output: 4.
Ans: In this problem, if we consider all zeros as plus 1 and all ones as -1, then this problem becomes the find max subarray problem. So if we use Kadane's Algorithm then we can find the answer in O(n) time complexity and space complexity will be O(1).
Code: