0981-0990

981. Time Based Key-Value Store $\star\star$

982. Triples with Bitwise AND Equal To Zero $\star\star\star$

983. Minimum Cost For Tickets $\star\star$

984. String Without AAA or BBB $\star\star$

985. Sum of Even Numbers After Queries $\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class Solution {
 public:
  vector<int> sumEvenAfterQueries(vector<int>& A,
                                  vector<vector<int>>& queries) {
    vector<int> ans;
    int sum = accumulate(A.begin(), A.end(), 0,
                         [](int a, int b) { return a + (b % 2 == 0 ? b : 0); });

    for (vector<int>& query : queries) {
      if (A[query[1]] % 2 == 0) sum -= A[query[1]];
      A[query[1]] += query[0];
      if (A[query[1]] % 2 == 0) sum += A[query[1]];
      ans.push_back(sum);
    }

    return ans;
  }
};

986. Interval List Intersections $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
 public:
  vector<vector<int>> intervalIntersection(vector<vector<int>>& A,
                                           vector<vector<int>>& B) {
    vector<vector<int>> ans;
    short i = 0;
    short j = 0;

    while (i < A.size() && j < B.size()) {
      int start = max(A[i][0], B[j][0]);
      int end = min(A[i][1], B[j][1]);
      if (end >= start) ans.push_back({start, end});
      if (A[i][1] > B[j][1])
        ++j;
      else
        ++i;
    }

    return ans;
  }
};

987. Vertical Order Traversal of a Binary Tree $\star\star$

988. Smallest String Starting From Leaf $\star\star$

989. Add to Array-Form of Integer $\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution {
 public:
  vector<int> addToArrayForm(vector<int>& A, int K) {
    for (int i = A.size() - 1; i >= 0; --i) {
      A[i] += K;
      K = A[i] / 10;
      A[i] %= 10;
    }

    while (K > 0) {
      A.insert(A.begin(), K % 10);
      K /= 10;
    }

    return A;
  }
};

990. Satisfiability of Equality Equations $\star\star$