An onboarding tour can attach tooltips to elements at the horizontal positions in positions (in pixels, in no particular order, all different). The tour needs count tooltips, and they are easiest to read when they are far apart.
Write maxGap(positions, count) that chooses count of the positions so that the smallest distance between any two chosen positions is as large as possible, and returns that distance.
Input: positions = [1,2,8,4,9], count = 3 Output: 3
Choose 1, 4, and 8 (or 9): the closest pair is 3 apart. A gap of 4 can't fit three tooltips.
Input: positions = [10,0], count = 2 Output: 10
With two tooltips, use both ends.
2 <= count <= positions.length <= 1000000 <= positions[i] <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #173 Spread Out the Tooltips. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.