Finding the largest subarray with equal number of 0's and 1's

后端 未结 10 1947
我在风中等你
我在风中等你 2020-12-31 11:30

So, I have an array containing only 0\'s and 1\'s. I have to find out the largest subarray containing equal number of 0\'s and 1\'s. One can be a naive approach have complex

10条回答
  •  春和景丽
    2020-12-31 12:17

    Hash map implementation in O(n) time.

    int count=0, max_length=0;
            unordered_map mp;
            mp[0] = -1;
    
            for(int i=0; i

    Hope this code block helps.

提交回复
热议问题