Question: JAVA!! Equal Price A shop in HackerLand contains n items where the price of the th item is price ( l ] , In one

JAVA!! Equal Price
A shop in HackerLand contains n items where the price of the th item is price(l], In one operation, the price of any one item can be increased or decreased by 1.
Given q queries denoted by the array queryl, find the minimum number of operations required to make the price of all items equal to each queryll](0<=/< q).
Note: All queries are independent of each other, i.e., the original price of items is restored after the completion of each query.
Example:
Consider n=3, q=4, pricel]=[1,2,3), queryD =[3,2,1,5]
query[0]=3 The number of operations required =[2,1,0] tomake the price of all elements equal to 3. Total number ofoperations =2+1+0=3.
query[1]=2, operations required =[1,0,1],1+0+1=2
query[2]=1, operations required =[0,1,2],0+1+2=3
query(3]=5, operations required =[4,3,2],4+3+2=9
The answer is [3,2,3,9].
Function Description
Complete the function countMinimumOperations in the editor below.
countMinimumOperations has the following parameters:
int price[n]: the original prices of each item int querylq]: the queries
Returns
long_int[q]: the answers to the queries in their order of input
Constraints
15n52*105
15 pricell]<=10\deg
15 q<=2*105
1<= queryll]<=10\deg

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!