All Posts

Leetcode 2243: Calculate Digit Sum of a String

You are given a string of digits, s, and an integer k. Your task is to repeatedly process the string until its length becomes less than or equal to k. In each step, divide the string into consecutive groups of size k. If the last group is smaller than k, process it as is. For each group, calculate the sum of its digits, convert the result back to a string, and merge all groups to form a new string. Repeat the process until the string length is ≤ k, and return the final string.

Leetcode 2257: Count Unguarded Cells in the Grid

You are given a 0-indexed grid of size m x n. Some cells in the grid are occupied by guards, and some by walls. A guard can observe all cells in the four cardinal directions (north, east, south, and west) from its position unless blocked by a wall or another guard. A cell is considered guarded if at least one guard can see it. Your task is to determine the number of cells that are unoccupied and are not guarded.

Leetcode 2293: Min Max Game

You are given an integer array nums where the length of the array is a power of 2. The task is to apply a repeated algorithm to reduce the array size. In each iteration, if the index of an element is even, the new value at that index will be the minimum of two adjacent elements; if the index is odd, the new value will be the maximum. The process continues until only one element remains, which is the result.

Leetcode 2295: Replace Elements in an Array

You are given a list of distinct positive integers, nums, and a list of operations. Each operation consists of two elements: operations[i][0] and operations[i][1]. In each operation, you need to replace the element operations[i][0] in nums with the new value operations[i][1]. The number operations[i][1] is guaranteed to not already be in nums. After performing all the operations, return the final array.

Leetcode 2326: Spiral Matrix IV

You are given two integers, m and n, which represent the dimensions of a matrix. You are also given the head of a linked list of integers. Your task is to generate an m x n matrix by filling it in a spiral order (clockwise) using the integers from the linked list. If any spaces remain, fill them with -1.

Leetcode 2327: Number of People Aware of a Secret

On day 1, one person discovers a secret. Each person will share the secret after a delay and forget it after a certain number of days. Return the number of people who know the secret at the end of day n, modulo 10^9 + 7.