Maximize Score of Numbers in Ranges

You are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d].

You are asked to choose n integers where the i^th integer must belong to the i^th interval. The score of the chosen integers is defined as the minimum absolute difference between any two integers that have been chosen.

Return the maximum possible score of the chosen integers.

Example 1
Inputstart = [6,0,3], d = 2
Output4
The maximum possible score can be obtained by choosing integers 8, 0, and 4, whose minimum pairwise absolute difference is 4.
Example 2
Inputstart = [2,6,13,13], d = 5
Output5
The maximum possible score can be obtained by choosing integers 2, 7, 13, and 18, whose minimum pairwise absolute difference is 5.

Constraints

  • 2 <= start.length <= 10^5
  • 0 <= start[i] <= 10^9
  • 0 <= d <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate