Fruit Stall Turned Away
Easy · hash map
A fruit stall opens in the morning with a delivery. The list delivered has one entry for every piece of fruit that arrived, written as the fruit's name: ["apple", "pear", "apple"] means two apples and one pear.
Then customers come to the stall one after another. The list orders gives what each customer asks for, in the order they arrive: customer 0 first, then customer 1, and so on. Every customer wants exactly one piece of the fruit they name.
If the stall still has a piece of that fruit, the customer buys it and the stall has one less. If the stall has run out of that fruit (or never had any), the customer leaves with nothing.
Return the numbers of the customers who left with nothing, in increasing order. If everybody was served, return an empty list.
Examples
Example 1
Input: delivered = ["apple", "pear", "apple"], orders = ["apple", "plum", "apple", "apple", "pear", "pear"]
Output: [1, 3, 5]
Customer 0 and customer 2 buy the two apples. Customer 1 wants a plum, which the stall never had. Customer 3 finds the apples gone. Customer 4 buys the only pear, so customer 5 finds none.
Example 2
Input: delivered = ["fig"], orders = ["fig"]
Output: []
The single fig is sold, and nobody leaves with nothing.
Constraints
- 1 <= len(delivered) <= 10^4
- 1 <= len(orders) <= 10^4
- Every name is 1 to 10 lowercase letters.