Trains the technique from
LeetCode 3661Maximum Walls Destroyed by RobotsThis 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.
Turrets stand on a line at the distinct positions given by robots, and turret i has a reach of distance[i]. Panels stand at the distinct positions given by walls.
Each turret fires exactly one shot, and you choose whether that shot goes left or right. A shot from a turret at position p with reach d sweeps every position from p out to d away in the chosen direction, p itself included, except that it is stopped short by the next turret in that direction: it never reaches or passes that turret's position.
A panel is broken when at least one shot sweeps its position. Return the greatest number of panels that can be broken.
Example 1
Both turrets firing right is best. The turret at 5 is stopped just short of the one at 9, so it sweeps 5 to 8 and breaks the panels at 5, 6, 7 and 8; the turret at 9 sweeps 9 to 19 and breaks those at 9, 10 and 11. That is seven, and only the panel at 4 is left.
Example 2
Nothing blocks the single turret, so firing left sweeps 7 to 10 and breaks the one panel.
Example 3
The turrets sit right beside each other, so every shot is stopped at once and sweeps only the turret's own position. All three panels sit under turrets, so all three break.
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_walls(robots: list[int], distance: list[int], walls: list[int]) -> int:public int maxWalls(int[] robots, int[] distance, int[] walls)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.