Prove the checker before searching
Connect greedy scans, capped arithmetic, and two-pointer counts to answer search.
Understand the idea
For nonnegative sequence partitioning, greedily extend each segment while its sum fits a capacity; starting a new segment only when necessary minimizes the number of segments for that capacity. For maximum minimum spacing, placing the next item at the earliest valid position leaves at least as much room for later placements.
Trace a small example
Partition [7, 2, 5, 10, 8] into at most two contiguous groups. Capacity 17 needs three groups, but 18 allows [7, 2, 5] and [10, 8]. For kth pair distance, sort first, count pairs with distance ≤ d using two pointers, and search the smallest d whose count reaches k.
Conditions and cost
The partition proof depends on nonnegative values. Count duplicate positions as distinct pairs. Saturate a count once it reaches the required threshold instead of overflowing. Include the O(n) checker and initial sorting in total complexity.
What makes an answer search correct besides a correct binary-search loop?
Turn the idea into code
Place 3 items among sorted coordinates [1, 2, 4, 8, 9] to maximize the minimum gap.
Give me a hint
Try gaps 3 and 4 using the earliest possible placement.
Show the explained solution
Gap 3 works with 1, 4, 8. Gap 4 places 1 and 8 but cannot place a third, so the optimum is 3.
Your notes
Mark complete when you can explain it yourself.