FastPrepMaximizing Difference in Array Elements with Moves 🐹
Problems/Maximizing Difference in Array Elements with Moves 🐹

Maximizing Difference in Array Elements with Moves 🐹

Microsoft logoMicrosoft● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem 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. 1. int[] A: an array of integers
  2. 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 = 1

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

A = [-5, 1, 1, 4, 4, 4, 7, 4, 6]K = 6return = 7

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

A = [-7, -6, -3, -2, -2, -2, -2, -2, -2, -2, -2, -1]K = 5return = 3

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

A = [6, 6, 6, 6, 6, 6]K = 3return = 1

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].

More Microsoft interview questions

  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026

Similar questions at other companies

  • Find Minimum TimeRippling · OARippling interview questions
  • Minimum Days to Target EngagementTikTok · OATikTok interview questions
  • Job ExecutionSnowflake · OASnowflake interview questions
  • Job ExecutionAdobe · OAAdobe interview questions
  • Minimum Time to Publish Comic BooksNutanix · OANutanix interview questions
  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Minimize Maximum Group DifferenceDRW · OADRW interview questions
  • Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
  • K-Means ClusteringFortinet · OAFortinet interview questions

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int maximizeDifference(int[] A, int K) {
        // write your code here
    }

}
Checking account…