this is the code a question which uses greedy approach, can someone help what is happening at line 5 i.e., how the value of ‘now’ getting updated?
def calculate():
arr=[30, 15, 60, 75, 45, 15, 15, 45]
last,now=0,0
for i in arr:
last,now=now,max(last+i,now)
return now
>Solution :
The line is basically the same as:
temp = last
last = now
now = max(temp+i, now)