Trains the technique from
LeetCode 598Range Addition IIThis 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 greenhouse holds a rectangular block of seedling trays with rows rows and cols columns. Rows are numbered 1 to rows from the back wall forward, columns 1 to cols from the left wall rightward.
The irrigation arm runs a list of watering passes. Pass [a, b] sweeps the corner block anchored at row 1 and column 1: it waters every tray whose row number is at most a and whose column number is at most b, adding one to that tray's watering count. Every tray starts at a count of 0.
After all passes have run, return how many trays share the highest watering count in the greenhouse. If passes is empty, every tray is still tied on a count of 0.
Example 1
The first pass waters rows 1 to 3 and columns 1 to 2, the second waters rows 1 to 2 and columns 1 to 4. Trays (1,1), (1,2), (2,1) and (2,2) end on a count of 2 and no tray reaches 3, so four trays share the highest count.
Example 2
Trays in rows 1 to 2 and columns 1 to 3 are touched by both passes, giving them a count of 2, while every other watered tray sits at 1. That block holds six trays.
Example 3
No pass runs, so all twelve trays still hold a count of 0 and every one of them ties for the highest count.
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 max_watered_trays(rows: int, cols: int, passes: list[list[int]]) -> int:public int maxWateredTrays(int rows, int cols, int[][] passes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.