Dsa
Two Pointers
Hard
Minimize Maximum Difference
You are given an array of integers representing heights of towers. Your goal is to minimize the maximum difference between the heights of the tallest and shortest towers after performing up to k height adjustments (you can only increase or decrease). Implement a function that reads from standard input and outputs the minimized maximum difference.
Example:
Input:
5 2
1 5 3 7 10
Output:
3
Input Description:
The first line contains two integers n and k (1 ≤ n ≤ 10^5, 0 ≤ k ≤ 1000). The second line contains n space-separated integers representing the heights of the towers.
Key concepts
two_pointerssortingoptimization
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now