A supermarket has many customers entering and exiting at various points. They want to keep track of customers and get notification when a customer leaves the store.
There are number of checkout lines, where customers with basket of items queue to pay and exit the store. Individual checkout lines and customers are assigned numerical IDs.
As happens in life, sometimes customers want to add more items to their baskets and sometimes they realise that they don't need certain items they picked up earlier and remove them from the basket.
To enforce checkout priorities a few rules have been implemented in the supermarket:
A customer will leave the supermarket as soon as they have no items left to checkout. Note that the lines with smaller IDs are closer to the exit, so if two customers pass the checkout line at the same time, the one closer to the exit would leave the store first.
Problem Statement
You will receive the stream of N instructions. Each instruction can be one of the following actions:
CustomerEnter
- indicates that a customer joined a checkout line. Attributes: CustomerId, LineNumber and NumItems.BasketChange
- indicates that a customer changed number of items in their basket. Attributes: CustomerId and NewNumItems.LineService
- indicates that several items have been processed in the line. Attributes: LineNumber and NumProcessedItems.LineService
- indicates that 1 item has been processed in every line (if there are k lines then in total k items are processed).Explanation
There are 2 customers (123 and 2) queued on two lines (1 and 2). When first LineService is called on both lines, both queued customers still have some items to check out. Namely, customer 123 has still 4 items, and customer 2 has 2 items to checkout.
Then customer 3 joins to the 1st line.
After next LineService on the 1st line, both customers with 123 and 3 IDs are checked out (first 123, and then 3). Customer 2 is still in the line.
Example 1:
Input: instructions = ["CustomerEnter 123 1 5", "CustomerEnter 3 1 2", "LineService 1 4", "BasketChange 123 6", "LineService 1 5"]
Output: [3, 123]
Explanation:Upon first LineService 4 out of 5 items of customer 123 are processed. However, customer then increases the number of items in their basket (namely adds 1 extra item), this puts them at the back of the line.
During the next LineService call customer 3 is checked out first, and customer 123 is checked out next (as they only had 2 items left to process).
N/A
input:
output: