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 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.

Leetcode 2224: Minimum Number of Operations to Convert Time

You are given two 24-hour formatted times, current and correct. Each time is represented in the format ‘HH:MM’, where HH is the hour (00 to 23) and MM is the minutes (00 to 59). In one operation, you can increase the current time by 1, 5, 15, or 60 minutes. Your task is to determine the minimum number of operations required to convert the current time to the correct time.

Leetcode 2233: Maximum Product After K Increments

You are given an array of non-negative integers and an integer k. In one operation, you can choose any element from the array and increment it by 1. Your task is to determine the maximum product of the array elements after at most k operations. The result should be returned modulo 10^9 + 7.