[LeetCode] Maximum Total Area Occupied by Pistons

3279. Maximum Total Area Occupied by Pistons

There are several pistons in an old car engine, and we want to calculate the maximum possible area under the pistons.

You are given:

  • An integer height
  • An integer array positions, where positions[i] is the current position of piston i
  • A string directions, where directions[i] is the current moving direction of piston i, 'U' for up, and 'D' for down.

Each second:

  • Every piston moves in its current direction 1 unit. e.g., if the direction is up, positions[i] is incremented by 1.
  • If a piston has reached one of the ends, i.e., positions[i] == 0 or positions[i] == height, its direction will change.

Return the maximum possible area under all the pistons.

Read more
[Codeforces] Round 946 (Div. 3) E. Money Buys HappinessRead more
[Codeforces] Round 945 (Div. 2) C. Cat, Fox and Double MaximumRead more
[Codeforces] Round 944 (Div. 4) G. XOURRead more
[Codeforces] Round 944 (Div. 4) F. Circle PerimeterRead more
[Codeforces] Helvetic Coding Contest 2024 online mirror (teams allowed, unrated) G1. Min-Fund Prison (Easy)Read more
[Codeforces] Helvetic Coding Contest 2024 online mirror (teams allowed, unrated) E1. Trails (Easy)Read more
[LeetCode] Sum of Digits of String After Convert

1945. Sum of Digits of String After Convert

You are given a string s consisting of lowercase English letters, and an integer k.

First, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, …, 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.

For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations:

  • Convert: "zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124
  • Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17
  • Transform #2: 17 ➝ 1 + 7 ➝ 8

Return the resulting integer after performing the operations described above.

Read more
[Marisa OJ] Permutation problemRead more
[Marisa OJ] Good string pairsRead more