The two-part output is what trips you up if you're not paying attention.
This is a classic 'next smaller or equal element' problem. Use a monotonic stack to efficiently find the first item to the right with price <= current for each item. Then compute the discounted prices, sum them, and collect indices of items with no discount.
Pro tip: Clarify edge cases upfront: what if multiple items have the same price? The problem says 'less than or equal', so equal prices count. Also, confirm whether the discount is subtracted from the original price or the already discounted price (it's original).
Restate the problem in your own words: for each item, find the first item to its right with price <= current price; subtract that price from the current price; sum all final prices; and list indices (0-based or 1-based?) of items with no discount.
Use a monotonic stack to find the next smaller or equal element for each item in O(n) time. The stack stores indices of items with prices in increasing order from bottom to top.
Iterate through the price list. For each price, while the stack is not empty and the current price <= price at stack top, pop the top and record the current index as the next smaller or equal for that popped index. Push the current index onto the stack. After iteration, remaining indices have no discount.
For each item, if it has a next smaller or equal, final price = original price - next price; else final price = original price. Sum all final prices. Collect indices of items with no discount.
Time complexity O(n) because each index is pushed and popped at most once. Space O(n) for the stack. Discuss edge cases: empty list, single item, all increasing, all decreasing, duplicates.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.