Trains the technique from
LeetCode 2503Maximum Number of Points From Grid QueriesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A survey grid records the silt depth of each cell, given as grid with m rows and n columns.
A dredger works one budget at a time. For a budget b it starts at the cell in row 0, column 0 and repeatedly moves to a cell sharing an edge with a cell it has already cleared. A cell may be cleared only when its recorded depth is strictly less than b, and that includes the starting cell: if the starting cell is not shallow enough, nothing is cleared at all. Each cell is counted once however often it is visited.
queries[i] holds the budget for the i-th run, and the runs are independent of each other. Return an array cleared where cleared[i] is how many cells the i-th run can clear.
Example 1
Under a budget of 5 the dredger clears the cells recording 1, 2, 3, 2 and 3, which is five cells. Under a budget of 2 only the opening cell recording 1 is shallow enough, so one cell is cleared.
Example 2
The opening cell records a depth of 5, which is not below the budget of 3, so nothing at all is cleared.
Example 3
The dredger clears 1, then 2 to its right, then 3 below that, then 4 below that, then 5 to the left of the 4, which is five cells.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def cells_cleared(grid: list[list[int]], queries: list[int]) -> list[int]:public int[] cellsCleared(int[][] grid, int[] queries)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.