Minimize Maximum Difference Between Adjacent Elements
You are provided with a non-decreasing array and an integer K. Your task is to remove exactly K elements from this array so that the maximum difference between any two adjacent elements in the remaining array is minimized.
Example:
Input:
array = [2, 6, 7, 7, 10], K = 2
Output:
1
Explanation:
By removing elements 2 and 10, the resulting array [6, 7, 7] has differences {1, 0}. The maximum difference is 1, which is the minimum possible in this scenario.
Constraints:
1 ≤ T ≤ 100
3 ≤ N ≤ 1000
1 ≤ A[i] ≤ 10^6
0 ≤ K ≤ N - 2
- Time Limit: 1 second
Be the first one to answer
Add answer anonymously...
Top Urban Company Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Urban Company Software Developer
>
Urban Company Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app