Minimum Danger Circular Arrangement
MediumP3Coding
N people with anger values anger[i] are to be seated around a circular table, in any order. The danger of an arrangement is the largest absolute difference in anger between two people sitting next to each other (the first and last seats are also neighbours). Return the smallest danger that any arrangement can achieve. With a single person, the danger is 0.
Example 1
- Input
- anger = [5,6,8,10]
- Output
- 4
- Why
- Seat them 5, 6, 10, 8 around the circle: the differences are 1, 4, 2 and 3.
Example 2
- Input
- anger = [1,9]
- Output
- 8
Constraints
- 1 <= N <= 10^5
- 1 <= anger[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.