All Posts

Leetcode 2250: Count Number of Rectangles Containing Each Point

You are given a 2D integer array rectangles, where each element rectangles[i] = [li, hi] represents a rectangle with a bottom-left corner at (0, 0), a length li, and a height hi. Additionally, you are provided a 2D integer array points, where each element points[j] = [xj, yj] represents a point on a 2D plane. The task is to determine the number of rectangles that contain each point. A rectangle contains a point if the point satisfies 0 <= xj <= li and 0 <= yj <= hi. Points on the edges of rectangles are also considered to be inside.

Leetcode 2255: Count Prefixes of a Given String

Given a list of strings words and a target string s, count how many strings in words are prefixes of s. A prefix is defined as a substring starting from the beginning of a string and extending up to a given length. Note that duplicate strings in words should be counted separately.

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.