Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A shopkeeperelis nitems where the price of the thitem is pricelmaintain balance, the shopkeeperwishes to adjust the price of items such that the median of
A shopkeeperelis nitems where the price of the thitem is pricelmaintain balance, the shopkeeperwishes to adjust the price of items such that the median of prices is exactly k In one move, the shopkeeper can increase or decrease the price of any item by and the shopkeeper can perform this move any number of times.Find the minimum number of moves in which the median of prices becomes exactly kNote: The index of the median of an array of m sorted elements, where m is odd, is m For example, sorted is Its length is so the median is at index using based indexing. The median is ExampleConsider n price and k Decrease price by the resulting array is ; on sorting, this becomes whosemedian equals k Thus, in one move, the medianbecomes and the answer is Function DescriptionComplete the function getMinimumMoves in the editor below
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started