Trains the technique from
LeetCode 3464Maximize the Distance Between Points on a SquareThis 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 square fence has its corners at (0, 0), (side, 0), (side, side) and (0, side). Candidate posts are given as points, each [x, y] lying on the fence itself, and all of them are distinct.
Choose k of the posts. The spread of a choice is the smallest distance between any two posts chosen, measured as the difference in x plus the difference in y.
Return the largest spread any choice of k posts can have.
Example 1
Taking the four corners leaves every neighbouring pair 12 apart, and no choice of four posts spreads them further.
Example 2
Every post on the fence has to be taken, and the closest neighbouring pair sits one apart.
Example 3
Only the four corners are on offer, so the spread is the side length itself.
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_distance(side: int, points: list[list[int]], k: int) -> int:public int maxDistance(int side, int[][] points, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.