[LeetCode] Maximize the Total Height of Unique Towers

3301. Maximize the Total Height of Unique Towers

You are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the ith tower can be assigned.

Your task is to assign a height to each tower so that:

  1. The height of the ith tower is a positive integer and does not exceed maximumHeight[i].
  2. No two towers have the same height.

Return the maximum possible total sum of the tower heights. If it’s not possible to assign heights, return -1.

Read more
[LeetCode] Minimum Element After Replacement With Digit Sum

3300. Minimum Element After Replacement With Digit Sum

You are given an integer array nums.

You replace each element in nums with the sum of its digits.

Return the minimum element in nums after all replacements.

Read more
[LeetCode] Sum of Consecutive Subsequences

3299. Sum of Consecutive Subsequences

We call an array arr of length n consecutive if one of the following holds:

  • arr[i] - arr[i - 1] == 1 for all 1 <= i < n.
  • arr[i] - arr[i - 1] == -1 for all 1 <= i < n.

The value of an array is the sum of its elements.

For example, [3, 4, 5] is a consecutive array of value 12 and [9, 8] is another of value 17. While [3, 4, 3] and [8, 6] are not consecutive.

Given an array of integers nums, return the sum of the values of all consecutive non-empty subsequences.

Since the answer may be very large, return it modulo 109 + 7.

Note that an array of length 1 is also considered consecutive.

Read more
[Codeforces] Round 961 (Div. 2) B2. Bouquet (Hard Version)Read more
[Codeforces] Round 959 sponsored by NEAR (Div. 1 + Div. 2) D. Funny GameRead more
[Codeforces] Round 959 sponsored by NEAR (Div. 1 + Div. 2) C. Hungry GamesRead more
[Codeforces] Round 957 (Div. 3) F. Valuable CardsRead more
[Codeforces] Pinely Round 4 (Div. 1 + Div. 2) E. Coloring GameRead more
[Codeforces] Round 957 (Div. 3) E. Novice`s MistakeRead more
[LeetCode] Count Substrings That Can Be Rearranged to Contain a String II

3298. Count Substrings That Can Be Rearranged to Contain a String II

You are given two strings word1 and word2.

A string x is called valid if x can be rearranged to have word2 as a prefix.

Return the total number of valid substrings of word1.

Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity.

Read more