Min Operations to Adjust Prices
The manager of the Amazon warehouse has decided to make changes to the inventory by changing the prices of the products.
Currently, the inventory has n products, where the price of the i-th product is represented by the array element prices[i].
The manager is given two integers:
k - which is the maximum amount by which a product's price can be adjusted (increased or decreased) in a single operation, andd - which represents the target price difference.
The goal is to ensure that the difference between the highest and lowest prices in the inventory is strictly less than d.
In order to make changes to the inventory, the manager can do the following operation any number of times:
x, y (1 ≤ x, y ≤ n), and an integer p (1 ≤ p ≤ k).x by p.y by p.
Given n products, an array prices, and the two integers k and d, find the minimum number of operations that the manager has to perform such that the maximum difference between the prices of any two products from the array of products is strictly less than d.
Complete the function minOperations in the editor.
minOperations has the following parameters:
int prices[n]: an array of integers representing the prices ofnproductsint k: the maximum amount that a price can be increased or decreased by in one operationint d: the target difference
Returns
int: the minimum number of operations required to ensure the condition is satisfied, i.e., the difference between the maximum and minimum prices of the array of products is strictly less than d.
1Example 1

2Example 2

Constraints
Limits and guarantees your solution can rely on.
- 1 ≤
n≤ 10^3 - 1 ≤
prices[i]≤ 10^3 - 1 ≤
k≤ 10^3 - 1 ≤
d≤ 10^3