Longest Subarray Length Time : Space : 1234567891011int Solution::solve(vector<int> &A) { int res = 0, now = 0; unordered_map<int, int> freq{{0,-1}}; for(int i = 0; i < A.size(); i++) { now += A[i] ? 1 : -1; if(!freq.count(now)) freq[now] = i; if(freq.count(now - 1)) res = max(res, i - freq[now-1]); } return res;}