Unfilled Orders
stock maps product names to the number of units on the shelf. orders is a list of product names, one unit per order, handled from first to last.
An order is filled when its product is in stock with at least one unit left, and filling it takes one unit off the shelf. Otherwise the order cannot be filled; a product that is not a key of stock has zero units. Return how many orders could not be filled. You may modify stock.
Example 1
stock {"apple":2,"pear":1}
orders ["apple","pear","pear","apple","apple"]
returns 2
The two apples and the one pear are filled in order; the second pear and the third apple find nothing left.
Example 2
stock {"milk":1}
orders ["bread","milk"]
returns 1
There is no bread at all; the milk order is filled.
Constraints
0 <= len(stock) <= 20and0 <= len(orders) <= 100- every unit count in
stockis between0and100 - names are 1 to 10 lowercase letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.