class Solution { public: int findMaxLength(vector<int>& nums) { int Max_length = 0; unordered_map<int,int> MP; int counter = 0; MP[counter] = -1; for(int i = 0;i<nums.size();i++) { int num = nums[i]; if(num == 1) { counter++; } else { counter--; } if(MP.count(counter)) { int current_id = MP[counter]; Max_length = max(Max_length,i-current_id); } else{ MP[counter] = i; } } return Max_length; } };