[eBay] OA 2025 Start – 02 Feb (Generic)

Your task is to implement a simplified inventory tracking system for a large retail store.

You are given a transaction log, where each log item corresponds to one of three transaction types: supply, sell, or return. Log items are provided in the following format:

  • ["supply", "", , ] – the store receives units of , and each item costs .
  • ["sell", "", ] – the store sells units of . If the specified item is available at different prices, the cheapest ones should be sold first. It is guaranteed that the store will always have enough items to satisfy all sell transactions.
  • ["return", "", , , ] – the store takes back units of . It is guaranteed that the store has sold at least units of previously at price = , which were not returned yet. The returned items can be added back to inventory and sold later at price = .

The tracking system should return the revenue from all sell transactions after processing the entire transaction log. Specifically, return an array representing the amount of money the store received from each sell transaction.

Notes:

  • You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(logs.length²) will fit within the execution time limit.

Imagine you are creating an algorithm for currency trading. Now you have a prototype which handles trading of a single currency. Each day, it can sell or buy exactly one unit of the currency or do nothing.

You are given rates, an array of positive integers where rates[i] represents the currency price on the ith day. You're also given strategy, an array of -1s, 0s, and 1s, where strategy[i] represents what operation the algorithm should perform on the ith day:

  • -1 represents the buy operation.
  • 0 represents the hold operation, meaning nothing is bought or sold.
  • 1 represents the sell operation.

It is also guaranteed that the number of -1s in strategy is guaranteed to be even.

In order to improve the algorithm's performance, you may change the strategy in the following way:

  • Choose a range of exactly k consecutive elements.
  • Set elements of the first half of the chosen range to 0.
  • Set elements of the second half of the chosen range to 1.

Your task is to choose the range optimally to maximize the algorithm's total profit. The profit is defined as the sum of all selling rates minus the sum of all buying rates (in other words, the difference between the end and start amount). The profit may be negative in case the end amount is lower than the start amount.

Note:

Assume it is always possible to perform buy and sell operations, meaning you always have enough currency and budget.

Leave a Reply

Your email address will not be published. Required fields are marked *