All Posts

Leetcode 2033: Minimum Operations to Make a Uni-Value Grid

You are given a 2D grid of integers, and an integer x. In each operation, you can either add x or subtract x from any element in the grid. Your task is to transform the grid into a uni-value grid, where all elements are equal. Return the minimum number of operations needed to achieve this, or return -1 if it is not possible.

Leetcode 2038: Remove Colored Pieces if Both Neighbors are the Same Color

You are given a string colors consisting of two types of pieces, ‘X’ and ‘Y’, arranged in a line. Two players, Alex and Brian, play a game where they take turns removing pieces from the string. Alex moves first and can only remove a piece ‘X’ if both its neighbors are also ‘X’. Similarly, Brian can only remove a piece ‘Y’ if both its neighbors are also ‘Y’. Neither player can remove edge pieces. If a player cannot make a move, they lose. Determine whether Alex wins the game if both players play optimally.

Leetcode 2048: Next Greater Numerically Balanced Number

An integer x is numerically balanced if, for every digit d in x, the digit d occurs exactly d times in the number. For example, 22 is numerically balanced because the digit 2 appears exactly 2 times, while 3133 is numerically balanced because the digit 3 appears exactly 3 times, and the digit 1 appears exactly 1 time.

Given an integer n, find the smallest numerically balanced integer that is strictly greater than n.

Leetcode 2063: Vowels of All Substrings

You are given a string word consisting of lowercase English letters. Your task is to return the total sum of the number of vowels (‘a’, ’e’, ‘i’, ‘o’, and ‘u’) present in every possible substring of word. A substring is any contiguous sequence of characters in the word.

Leetcode 2101: Detonate the Maximum Bombs

You are given a list of bombs represented by a 2D array ‘bombs’ where each bomb is described by three integers: [xi, yi, ri]. xi and yi denote the X and Y coordinates of the bomb, while ri is its blast radius. Your task is to find the maximum number of bombs that can be detonated by initiating a detonation of one bomb.

Leetcode 2110: Number of Smooth Descent Periods of a Stock

You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day. A smooth descent period of a stock consists of contiguous days such that the price on each day decreases by exactly 1 from the previous day. The first day of the period can be a single-day smooth descent. Return the total number of smooth descent periods.