Description
Solutions
Maximizing Difference in Array Elements with Moves πΉ
π₯ FULLTIMEπRELATED PROBLEMS
Given an array A
of integers (size N
, divisible by 3) and an integer K
representing the maximum number of moves allowed, you can increase or decrease any element in A
by 1 per move. The goal is to maximize the difference between the N/3
-th largest and N/3
-th smallest elements in A
after using up to K
moves.
Function Description
Complete the function maximizeDifference
in the editor.
maximizeDifference
has the following parameters:
- 1.
int[] A
: an array of integers - 2.
int K
: the maximum number of moves allowed
Returns
int: the maximum difference that can be achieved
Example 1:
Input: A = [8, 8, 8, 7, 7, 7, 7, 7, 7, 7, -8, -8], K = 1
Output: 1
Explanation:No explanation is provided for now π³π« As always, I will add it once find any. Or if you happen to know about it, feel free to dm Groot! Many thanks in advance! π«Ά
Example 2:
Input: A = [-5, 1, 1, 4, 4, 4, 7, 4, 6], K = 6
Output: 7
Explanation:No explanation is provided for now π³π« As always, I will add it once find any. Or if you happen to know about it, feel free to dm Groot! Many thanks in advance! π«Ά
Example 3:
Input: A = [-7, -6, -3, -2, -2, -2, -2, -2, -2, -2, -2, -1], K = 5
Output: 3
Explanation:No explanation is provided for now π³π« As always, I will add it once find any. Or if you happen to know about it, feel free to dm Groot! Many thanks in advance! π«Ά
Example 4:
Input: A = [6, 6, 6, 6, 6, 6], K = 3
Output: 1
Explanation:No explanation is provided for now π³π« As always, I will add it once find any. Or if you happen to know about it, feel free to dm Groot! Many thanks in advance! π«Ά
Constraints:
N
is an integer within[3..150,000]
, divisible by 3.K
is an integer within[0..500,000,000]
.- Each element of
A
is an integer within[-300,000,000..300,000,000]
.

Related Problems
Testcase
Result
Case 1
input:
output: