'Is this a correct solution to the question below?
Unexpected Demand A widget manufacturer is facing unexpectedly high demand for its new product.
They would like to satisfy as many customers as possible. Given a number of widgets available and a list of customer orders, what is the maximum number of orders the manufacturer can fulfill in full?
Function Description Complete the function filledOrders in the editor below. The function must return a single integer denoting the maximum possible number of fulfilled orders. filledOrders has the following parameter(s):
order : an array of integers listing the orders k : an integer denoting widgets available for shipment Constraints 1 ≤ n ≤ 2 x 105 1 ≤ order[i] ≤ 109 1 ≤ k ≤ 109
Sample Input For Custom Testing 2 10 30 40 Sample Output 2
My answer below:
def filledOrders(order, k):
total, count = 0, 0
for order in sorted(order):
pending_order = []
if order <= k:
pending_order.append(order)
for pends in pending_order:
if (total + pends) <= k:
count += 1
k -= pends
elif k == 0 or order == []:
count = 0
return count
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
