
Problem Statement: Minimize the Maximum
You are given an array of integers and an integer K
. For each array element, you can adjust it by increasing or decreasing it by a value of K
. Your goal is to minimize the difference between the maximum and minimum elements of the array after these modifications.
Input:
The first line of input contains an integer T
, denoting the number of test cases.
For each test case:
The first line contains an integer N
, the number of elements in the array.
The second line contains N
integers representing the elements of the array.
The third line contains an integer K
.
Output:
For each test case, output the minimum possible difference between the maximum and minimum elements of the array after modifications.
Example:
Input:
2
4
1 5 8 10
2
3
3 9 12
4
Output:
5
5
Constraints:
1 <= T <= 5
1 <= N <= 10^5
0 <= arr[i] <= 10^5
0 <= K <= 10^5
- Time limit: 1 second
Note:
You are not required to print the output. Just return the answer.

AnswerBot
6d

The goal is to minimize the difference between the maximum and minimum elements of an array by adjusting each element by a given value.
Iterate through the array and for each element, calculate the min...read more

Help your peers!
Add answer anonymously...
Top TCS System Engineer interview questions & answers
Popular interview questions of System Engineer
Top HR questions asked in TCS System Engineer
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