classSolution { public: intlongestWPI(vector<int>& hours){ int n = hours.size(); unordered_map<int, int> count; int cur = 0; int res = 0; for (int i = 0; i < n; ++i) { if (hours[i] > 8) { cur++; } else { cur--; } if (cur > 0) res = i + 1; else { if (count.count(cur-1) > 0) res = max(res, i - count[cur-1]); if (count.count(cur) < 1) count[cur] = i; } } return res;