Company: Amazon_4th june_on campus _iit guwahti

Difficulty: medium

Problem Statement

The manager of a retail warehouse wants to rebalance the inventory by adjusting product prices. The inventory holds n products, where the price of the i th product is given by array element prices[i]. The manager is given two integers: k, the largest amount by which any single price adjustment can move a product's price (up or down), and d, a target gap. The goal is to make the difference between the highest and lowest prices in the inventory strictly smaller than d. To rebalance the inventory, the manager may repeat the following operation any number of times: The manager selects two indices x, y (1 ≤ x, y ≤ n), and an integer p (1 ≤ p ≤ k). The manager increases the price of the product x by p. The manager decreases the price of the product y by p. Given n products, an array prices, and the two integers k and d, work out the fewest operations the manager must perform so that the gap between the highest and lowest prices among all products becomes strictly less than d. Not

More Amazon_4th june_on campus _iit guwahti OA questionsInterview experiences