Get Minimum Moves

Problem Overview

  • Given n item prices and a target k, find the minimum number of +1/−1 price changes so the sorted array’s median equals k.
  • Input: price[n] and k (n is odd); Output: a long integer with the minimal moves.
  • Constraints: 1 ≤ n ≤ 100000, 1 ≤ price[i], k ≤ 1e9.
  • Real-world context: adjusting shop prices to balance around a desired median.
  • This interview question from Ibm interviews is a common coding interview problem.

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: