All Posts

Leetcode 1910: Remove All Occurrences of a Substring

Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed. Find the leftmost occurrence of the substring part and remove it from s. Return s after removing all occurrences of part.

Leetcode 1911: Maximum Alternating Subsequence Sum

You are given an array nums. The alternating sum of a sequence is calculated as the sum of elements at even indices minus the sum of elements at odd indices. Your task is to find the maximum alternating sum of any subsequence formed by deleting some elements from the array without changing the relative order of the remaining elements.

Leetcode 1914: Cyclically Rotating a Grid

You are given an m x n integer matrix grid, where both m and n are even integers, and an integer k. The matrix consists of several concentric layers, and each layer can be thought of as a circular band of numbers. A cyclic rotation of a layer is done by shifting all its elements counter-clockwise by one position. You are asked to return the matrix after applying k cyclic rotations to each of its layers.

Leetcode 1915: Number of Wonderful Substrings

A string is considered wonderful if at most one letter appears an odd number of times. Given a string word consisting of the first ten lowercase English letters (‘a’ through ‘j’), return the total number of wonderful non-empty substrings in the string word. If the same substring appears multiple times, each occurrence should be counted separately.

Leetcode 1921: Eliminate Maximum Number of Monsters

You are defending your city from a group of n monsters. You are given two arrays dist and speed, where dist[i] is the initial distance of the ith monster from the city, and speed[i] is the speed of the ith monster in kilometers per minute. Your weapon takes one minute to charge and can eliminate one monster once fully charged. The game ends if any monster reaches the city before your weapon is ready. Return the maximum number of monsters you can eliminate or n if all monsters can be eliminated before they reach the city.

Leetcode 1926: Nearest Exit from Entrance in Maze

You are given a maze and need to find the nearest exit from the entrance. An exit is defined as an empty cell on the border of the maze. Return the shortest path to the nearest exit, or -1 if no exit is reachable.