0941-0950

941. Valid Mountain Array $\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Solution {
 public:
  bool validMountainArray(vector<int>& A) {
    if (A.size() < 3) return false;

    int l = 0;
    int r = A.size() - 1;

    while (l + 1 < A.size() && A[l] < A[l + 1]) ++l;
    while (r > 0 && A[r] < A[r - 1]) --r;

    return l > 0 && r < A.size() - 1 && l == r;
  }
};

942. DI String Match $\star$

943. Find the Shortest Superstring $\star\star\star$

944. Delete Columns to Make Sorted $\star$

945. Minimum Increment to Make Array Unique $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Solution {
 public:
  int minIncrementForUnique(vector<int>& A) {
    int ans = 0;
    int minAvailable = 0;

    sort(A.begin(), A.end());

    for (int a : A) {
      ans += max(minAvailable - a, 0);
      minAvailable = max(minAvailable, a) + 1;
    }

    return ans;
  }
};

946. Validate Stack Sequences $\star\star$

947. Most Stones Removed with Same Row or Column $\star\star$

948. Bag of Tokens $\star\star$

949. Largest Time for Given Digits $\star$

950. Reveal Cards In Increasing Order $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Solution {
 public:
  vector<int> deckRevealedIncreasing(vector<int>& deck) {
    sort(deck.begin(), deck.end(), greater<int>());

    deque<int> deque = {deck[0]};

    for (int i = 1; i < deck.size(); ++i) {
      deque.push_front(deque.back());
      deque.pop_back();
      deque.push_front(deck[i]);
    }

    return vector<int>(deque.begin(), deque.end());
  }
};