Problem ยท Sorting
Maximizing Difference in Array Elements with Moves ๐น
Learn this problemProblem statement
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
maximizeDifference(A: int[], K: int) โ int
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
Examples
Example 1
A = [8, 8, 8, 7, 7, 7, 7, 7, 7, 7, -8, -8]K = 1return = 1No 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
A = [-5, 1, 1, 4, 4, 4, 7, 4, 6]K = 6return = 7No 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
A = [-7, -6, -3, -2, -2, -2, -2, -2, -2, -2, -2, -1]K = 5return = 3No 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
A = [6, 6, 6, 6, 6, 6]K = 3return = 1No 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
Nis an integer within[3..150,000], divisible by 3.Kis an integer within[0..500,000,000].- Each element of
Ais an integer within[-300,000,000..300,000,000].
More Microsoft problems
- Maximum Pipeline ThroughputOA ยท Seen Jul 2026
- Maximum Strong Team SubarrayOA ยท Seen Jul 2026
- Minimum Cost K-Capable ModelsOA ยท Seen Jul 2026
- Alphabetically Smallest PalindromeOA ยท Seen Jul 2026
- Maximum Reward PointsOA ยท Seen Jul 2026
- Maximum Strength of Every NeuronOA ยท Seen Jul 2026
- Neural Network Subnetwork StrengthOA ยท Seen Jul 2026
- XOR MultiplicationOA ยท Seen Jul 2026