Microsoft Phone screen | DP | Redmond WA
Sticks in inventory
Imagine there is a lumberyard that sells sticks. All my sticks are exactly the same except that they vary by length. You can cut the bigger sticks if you wish to make smaller sticks
Given an inventory and a order I.e. list of stick lengths that the customer would like to purchase
Check weather the order can be fulfilled or not.
Inventory: 10, 5, 2, 3, 10, 8
Order: 3, 2, 10, 9
Output: True
Inventory: 10, 9, 1
Order: 6, 5, 5, 3
Output: True
Solution:
another way to think of this problem, lets say we have a knapsacks 10, 9, 1
try to maximize the usage of each knapsack by filling it with weights from order
In the end if you can put all the weights into knapsacks you can return True
Eg: Here is how you can fill out the knapsacks in the inventory
10 --> 5,5
9 --> 6,3
Filled out each weight into a knapsack so True
time complexity:
m-->len(inventory
n-->len of order
M * (N * N)