Chocolates With Magical Number
1. Using this magical number, Ninja can either increase or decrease the sweetness of each chocolate. 2. After increasing or decreasing the sweetness, all the new sweetness values must be non-negative. 3. Ninja must use this magic number on each chocolate exactly once.
For ‘PACKETS’ = [1, 2, 3, 4, 5] and 'K' = 1, the absolute difference between two chocolates with maximum (5) and minimum (1) sweetness is 4. Now in order to minimize this value, Ninja increases [1, 2, 3] and decreases [4, 5] by 1 (‘K’ = 1). So, ‘PACKET’ becomes [2,3,4,3,4]. Now, the absolute difference between the two chocolates with maximum (4) and minimum (2) sweetness is 2 which is the minimum possible.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow. The first line of each test case contains two single space-separated integers 'N' and 'K' denoting the number of chocolates in the 'PACKET' and the magic number, respectively. The second line of each test case contains 'N' single space-separated integers, denoting the sweetness of each chocolate in 'PACKET'.
For each test case, print the minimum possible difference between the maximum and minimum sweetness value of chocolates in the array/list ‘PACKET’. Print the output of each test case in a separate line.
You are not required to print the expected output, and it has already been taken care of. Just implement the function.
1 <= T <= 100 1 <= N <= 10^5 1 <= K <= 10^5 1 <= PACKET[i] <= 10^5 Where 'T' is the number of test cases, 'N' denotes the number of chocolates in the given array/list 'PACKET' and 'K' denotes the given magic number, respectively. 'PACKET[i]' denotes the sweetness of the i'th chocolate. Time Limit : 1 sec
Longest Subarray With Zero Sum
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End