Company: Agoda_15dec

Difficulty: medium

Problem Statement

Final Price Final Price Problem Description A store lines up its merchandise for a clearance sale. Scanning from the left, every item's charged price is its listed price minus the price of the nearest item to its right whose price is equal to or lower. If no such item exists further along, the item is charged at its full listed price. Print the sum of the final charged price across all items, then on the next line print the space-separated, 0-based indices of the items that ended up being charged full price, listed in ascending order. Examples Example 1 For example, consider the item prices [2, 3, 1, 2, 4, 2] . Item at index 0, priced at 2, is discounted by 1 (item at index 2), final price is 1. Item at index 1, priced at 3, is discounted by 1 (item at index 2), final price is 2. Item at index 2, priced at 1, sells at full price as there are no equal or lower-priced items to its right. Item at index 3, priced at 2, is discounted by 2 (item at index 5), final price is 0. Item at index 4

More Agoda_15dec OA questionsInterview experiences