Untitled
unknown
plain_text
a year ago
974 B
8
Indexable
def countMaximumDays(lend, payback):
from bisect import bisect_left
n = len(lend)
# Create a list of lenders with their lend amount and payback
lenders = sorted(zip(lend, payback))
lend_amounts = [l[0] for l in lenders]
day = 0
prev_payback = 0 # No payback on the first day
start_idx = 0
while True:
if day == 0:
# On the first day, pick the lender with the smallest lend amount
lend_i, payback_i = lenders[start_idx]
start_idx += 1
prev_payback = payback_i
day += 1
else:
# Need to find a lender with lend >= prev_payback
left = bisect_left(lend_amounts, prev_payback, lo=start_idx)
if left == n:
break # No lender can satisfy the payback requirement
lend_i, payback_i = lenders[left]
start_idx = left + 1
prev_payback = payback_i
day += 1
return day
Editor is loading...
Leave a Comment