1121-1130

1121. Divide Array Into Increasing Sequences \star\star\star

1122. Relative Sort Array \star

1123. Lowest Common Ancestor of Deepest Leaves \star\star

1124. Longest Well-Performing Interval \star\star

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
 public:
  int longestWPI(vector<int>& hours) {
    int ans = 0;
    int presum = 0;
    unordered_map<int, int> map;

    for (int i = 0; i < hours.size(); ++i) {
      presum += hours[i] > 8 ? 1 : -1;
      if (presum > 0) {
        ans = i + 1;
      } else {
        if (!map.count(presum)) map[presum] = i;
        if (map.count(presum - 1)) ans = max(ans, i - map[presum - 1]);
      }
    }

    return ans;
  }
};

1125. Smallest Sufficient Team \star\star\star

1126. Active Businesses \star\star

1127. User Purchase Platform \star\star\star

1128. Number of Equivalent Domino Pairs \star

1129. Shortest Path with Alternating Colors \star\star

1130. Minimum Cost Tree From Leaf Values \star\star