Your task is to implement a simplified inventory tracker system for a large retail store. You are given a price list pricelist that describes the current market price for each item, and a transaction log logs where each record contains information about one of three types of transactions: sell, discount_start, or discount_end. The tracker should process all transactions and return the total revenue from all sales.
Each element in the price list follows this format: "<item_name>: <price>", which represents that <item_name> can be sold at the price of <price>.
Transactions are provided in the following format:
"sell <item_name>, <count>": the store sells<count>units of<item_name>."discount_start <item_name>, <discount_amount>, <max_count>": the store announces a discount, and now sells<item_name>at the price ofprice - <discount_amount>. However, only<max_count>units can be sold at the discounted price, and all additional units are sold at the original price.<max_count>can be at most100, and there can only be one discount for each item at any time."discount_end <item_name>": the store announces the end of the discount for<item_name>. It is guaranteed that the item has a discount at this point.
Note: All transactions are sorted chronologically.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(logs.length2 * pricelist.length) will fit within the execution time limit.
pricelist = ["item1: 100", "item2: 200"] logs = ["sell item1, 1", "sell item1, 2", "sell item2, 2", "discount_start item2, 40, 1", "sell item2, 2", "sell item1, 1", "discount_end item2", "sell item2, 1"] return = 1360
The transactions are processed in chronological order:
"sell item1, 1": revenue is1 * 100 = 100."sell item1, 2": revenue is2 * 100 = 200."sell item2, 2": revenue is2 * 200 = 400."discount_start item2, 40, 1":item2now has a discount of40for at most1unit."sell item2, 2": one unit is sold at200 - 40 = 160, and the other unit is sold at the original price of200, so revenue is160 + 200 = 360."sell item1, 1": revenue is1 * 100 = 100."discount_end item2": the discount foritem2ends."sell item2, 1": revenue is1 * 200 = 200.
The total revenue is 100 + 200 + 400 + 360 + 100 + 200 = 1360.
- Check Even-Position MonotonicityOA · Seen Jun 2026
- Count Alternating Tile GroupsOA · Seen Jun 2026
- Count Even-Digit NumbersOA · Seen Jun 2026
- Construct WDL StringOA · Seen Jun 2026
- Find Sum PairsOA · Seen Jun 2026
- LRU Cache with TTL ExpirationONSITE INTERVIEW · Seen May 2026
- Maximum Candies with At Most Two Types in a LineONSITE INTERVIEW · Seen May 2026
- Top-K KOLs by Total LikesONSITE INTERVIEW · Seen May 2026
public int solution(String[] pricelist, String[] logs) {
// write your code here
}