ORIGINAL CODING QUESTION
Shrink the longest unsupported stretch
Help desks sit at strictly increasing integer positions along a training campus road. You may open at most k new desks at any integer positions. Return the smallest possible length of the longest stretch between neighbouring desks. Only the road between the first and last existing desk matters, and with a single desk the answer is 0.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n k, then n strictly increasing desk positions. Print the smallest achievable longest stretch.
Constraints
1 ≤ n ≤ 200; 0 ≤ k ≤ 10,000; 0 ≤ position ≤ 100,000.
Example 1
Input
3 2 0 10 14
Output
4
Two new desks at 4 and 7 (or 3 and 7) split 10 into pieces of length at most 4; length 3 would need three desks.
Example 2
Input
2 0 5 12
Output
7
No new desks are allowed, so the stretch stays 7.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
If a longest stretch of D is achievable, any larger D is also achievable.
Hint 2
A gap of length g needs ceil(g / D) - 1 new desks to bring every piece down to at most D.
Hint 3
Binary search D between 1 and the largest gap; D is feasible when the total desks needed is at most k.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →