Maximizing Difference in Array Elements with Moves

Problem Overview

  • Task: maximize the difference between the N/3-th largest and N/3-th smallest elements by applying up to K ±1 moves on array values.
  • Input: integer array A (N divisible by 3) and integer K; output: the maximum achievable difference.
  • Constraints: N ∈ [3..150,000], K ∈ [0..500,000,000], A[i] ∈ [-300,000,000..300,000,000].
  • Context: array manipulation and optimization under a limited move budget, relevant to data processing scenarios.
  • Source: Microsoft interviews; a coding interview problem and common interview question on arrays.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: