Company: Microsoft_25july

Difficulty: medium

Problem Statement

Final Price Problem Description A resale marketplace lists items for sale in a fixed row. Scanning from the left, every item is sold at its listed price reduced by the price of the nearest item to its right whose price is equal to or lower than its own; if no such item exists further along the row, the item sells at its full listed price with no reduction. Print the sum of every item's final selling price, then on the next line print the 0-based indices, in ascending order and separated by spaces, of the items that ended up selling at full price. For example, take the listed prices [2, 3, 1, 2, 4, 2]. The items at indices 0 and 1 both get reduced by 1 unit, since that is the nearest equal-or-lower price sitting to their right. Item 2, listed at 1 unit, sells at full price because nothing further right is equal to or cheaper than it. Item 3, listed at 2 units, gets reduced by 2 units, landing at 0. Item 4, listed at 4 units, gets reduced by 2 units, landing at 2. The last item, listed a

More Microsoft_25july OA questionsInterview experiences