All Posts

Leetcode 2957: Remove Adjacent Almost-Equal Characters

You are given a 0-indexed string word. In each operation, you can change any character of word to a lowercase English letter. Two characters are considered almost-equal if they are the same or adjacent in the alphabet. Your task is to remove all adjacent almost-equal characters with the minimum number of operations.

Leetcode 2966: Divide Array Into Arrays With Max Difference

You are given an array nums of size n where n is a multiple of 3, and a positive integer k. Your task is to divide the array into n / 3 subarrays, each containing exactly 3 elements, such that the difference between the largest and smallest element in each subarray is less than or equal to k. If it’s possible to divide the array in this way, return a 2D array containing the subarrays. If it is not possible, return an empty array. If multiple valid divisions exist, return any valid one.

Leetcode 2971: Find Polygon With the Largest Perimeter

You are given an array nums consisting of positive integers. A polygon can be formed from the integers if it satisfies the following condition: the sum of the lengths of any k-1 sides must be greater than the length of the remaining side. The perimeter of a polygon is the sum of the lengths of its sides. Your task is to find the largest possible perimeter of a polygon that can be formed using the sides from nums, or return -1 if it is not possible to form such a polygon.

Leetcode 3081: Replace Question Marks in String to Minimize Its Value

You are given a string s consisting of lowercase English letters and question marks (?). Your task is to replace all occurrences of ? with any lowercase English letter in such a way that the total cost of the resulting string is minimized. The cost of a string is the sum of how many times each character has appeared before its current position. If there are multiple solutions with the same minimal cost, return the lexicographically smallest one.