All Posts

Leetcode 2202: Maximize the Topmost Element After K Moves

You are given an integer array nums representing a pile, where nums[0] is the topmost element. You can perform the following operations in exactly k moves:

  1. Remove the topmost element of the pile (if it’s not empty).
  2. If any elements have been removed, you can add any one of them back onto the pile as the new topmost element.

Your goal is to determine the maximum value that can be at the top of the pile after exactly k moves. If it is not possible to have any elements left in the pile after k moves, return -1.

Leetcode 2207: Maximize Number of Subsequences in a String

You are given a string text and another string pattern of length 2, consisting of lowercase English letters. Your task is to insert one of the characters from pattern into text exactly once, and then return the maximum number of times pattern appears as a subsequence in the modified text.

Leetcode 2208: Minimum Operations to Halve Array Sum

You are given an array nums of positive integers. In each operation, you can reduce any number in the array by half. Your goal is to return the minimum number of operations required to reduce the sum of the array by at least half.

Leetcode 2211: Count Collisions on a Road

You have n cars on a straight road, each numbered from 0 to n-1 from left to right, with each car positioned at a unique location. You are given a string directions where each character represents the direction of a car (‘L’ for left, ‘R’ for right, and ‘S’ for stationary). Each moving car has the same speed, and the cars can collide under the following conditions: Two cars moving in opposite directions (‘L’ and ‘R’) will collide, counting as 2 collisions. A moving car colliding with a stationary car (‘S’) will result in 1 collision. After a collision, the cars involved stay at the collision point and no longer move. Your task is to calculate the total number of collisions that will happen.

Leetcode 2212: Maximum Points in an Archery Competition

Alice and Bob are opponents in an archery competition. Alice first shoots numArrows arrows, followed by Bob, in the target scoring sections from 0 to 11. The goal is to maximize Bob’s total score, ensuring that the sum of arrows shot by Bob equals numArrows.

Leetcode 2216: Minimum Deletions to Make Array Beautiful

You are given an integer array nums. The array is considered beautiful if it satisfies the following conditions: the length of nums is even, and for every index i that is even (i % 2 == 0), nums[i] should not be equal to nums[i + 1]. You can remove any number of elements from nums to make it beautiful. Your goal is to return the minimum number of elements that need to be removed to make the array beautiful.