
Asked in TCS
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.
Be the first one to answer
Add answer anonymously...
Top System Engineer Interview Questions Asked at TCS
Q. How do you handle frames in Selenium?
Q. What synchronization methods have you used in Selenium?
Q. What is Java?
Interview Questions Asked to System Engineer at Other Companies
Top Skill-Based Questions for TCS System Engineer
Networking Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
Python Interview Questions and Answers
200 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

