1041-1050

1041. Robot Bounded In Circle $\star\star$

1042. Flower Planting With No Adjacent $\star$

1043. Partition Array for Maximum Sum $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution {
 public:
  int maxSumAfterPartitioning(vector<int>& A, int K) {
    const int n = A.size();
    vector<int> dp(n + 1);

    for (int i = 1; i <= n; ++i) {
      int min = INT_MIN;
      for (int j = 1; j <= std::min(i, K); ++j) {
        min = max(min, A[i - j]);
        dp[i] = max(dp[i], dp[i - j] + min * j);
      }
    }

    return dp[n];
  }
};

1044. Longest Duplicate Substring $\star\star\star$

1045. Customers Who Bought All Products $\star\star$

1046. Last Stone Weight $\star$

1047. Remove All Adjacent Duplicates In String $\star$

1048. Longest String Chain $\star\star$

1049. Last Stone Weight II $\star\star$

1050. Actors and Directors Who Cooperated At Least Three Times $\star$