All Posts

Leetcode 2256: Minimum Average Difference

You are given a 0-indexed integer array nums of length n. For each index i, calculate the absolute difference between the average of the first i + 1 elements and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer. Your task is to find the index i with the minimum average difference. If there are multiple indices with the same difference, return the smallest index.

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 2260: Minimum Consecutive Cards to Pick Up

You are given an array cards where each element represents a card’s value. A matching pair of cards occurs when two cards have the same value. Your task is to find the minimum number of consecutive cards you need to pick to guarantee that you have a pair of matching cards. If it’s impossible to find a matching pair, return -1.

Leetcode 2261: K Divisible Elements Subarrays

You are given an integer array nums and two integers k and p. Your task is to count the number of distinct subarrays where there are at most k elements divisible by p. A subarray is defined as a contiguous part of the array, and two subarrays are considered distinct if they differ in either length or at least one element.

Leetcode 2265: Count Nodes Equal to Average of Subtree

You are given the root of a binary tree. Your task is to return the number of nodes where the value of the node is equal to the average of the values in its entire subtree (including the node itself). The average of a set of values is the sum of the values divided by the number of values, rounded down to the nearest integer.

Leetcode 2266: Count Number of Texts

Alice is texting Bob using her phone’s keypad. Each digit from ‘2’ to ‘9’ maps to multiple letters, and Alice has to press a key several times to type each letter. However, due to a transmission error, Bob receives a string of digits corresponding to the number of key presses rather than the message itself. Your task is to determine how many possible messages Alice could have sent, given the sequence of digits Bob received. The answer should be returned modulo 1e9 + 7.