Trains the technique from
LeetCode 849Maximize Distance to Closest PersonThis 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 gym corridor has one row of lockers. lockers[i] is 1 when locker i is already assigned to somebody and 0 when it is free. At least one locker is free and at least one is assigned.
You get to claim one free locker. The quiet score of a locker is the number of doors between it and the closest assigned locker, that is |i - j| for the closest index j with lockers[j] == 1.
Return the largest quiet score you can claim.
Example 1
Claiming locker 2 puts two doors between it and locker 0, and two doors between it and locker 5.
Example 2
Claiming locker 0 puts three doors between it and locker 3, the only assigned one.
Example 3
Claiming locker 2 puts two doors between it and locker 0.
Example 4
Both free lockers sit next to an assigned locker on either side.
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_dist_to_closest(lockers: list[int]) -> int:public int maxDistToClosest(int[] lockers)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.