Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Magnetic Force Between Two Balls

Medium

Topics
ArrayBinary SearchSorting

Given an array nums of distinct basket positions and an integer target (= m balls), place the balls into baskets so that the minimum distance between any two balls is as large as possible. Return that maximum possible minimum distance.

Example 1

Input:  nums = [1,2,3,4,7], target = 3
Output: 3

Example 2

Input:  nums = [5,4,3,2,1,1000000000], target = 2
Output: 999999999

Constraints

  • 2 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9
  • All positions are distinct.
  • 2 <= target <= nums.length
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access