Question bank › Arrays
Dsa Arrays Hard

Minimize Array Range

You are given an array of integers representing the heights of mountains. Your task is to minimize the range of heights (the difference between the maximum and the minimum height) after modifying `k` heights. You can increase the height of a mountain by 1 at a time or decrease it by 1 at a time. After performing the operations, print the minimized range. The input consists of two lines; the first line contains two integers, `n` (the number of mountains) and `k` (the number of modifications allowed), and the second line contains `n` integers representing the heights of the mountains. Example: Input: 5 3 1 3 6 10 15 Output: 4

Key concepts

arrayssliding windowgreedy

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.