Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 pricel In one operation, the price of any one item can be increased or decreased by
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 q
Note: All queries are independent of each other, ie the original price of items is restored after the completion of each query.
Example:
Consider n q pricel queryD
query The number of operations required tomake the price of all elements equal to Total number ofoperations
query operations required
query operations required
query operations required
The answer is
Function Description
Complete the function countMinimumOperations in the editor below.
countMinimumOperations has the following parameters:
int pricen: the original prices of each item int querylq: the queries
Returns
longintq: the answers to the queries in their order of input
Constraints
n
pricelldeg
q
querylldeg
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