Theres also a really nice greedy solution to this also. Where it mentions 'You can buy it then immediately sell it on the same day.' Was something I overlooked at the start and wrote a solution like yours. Definitely worth noting to look for small bits of info like this in problems
My solution was this code : profit = 0 for i in range(len(prices)-1): diff = prices[i+1]-prices[i] if diff>0: profit += diff return profit No need to calculate low and high here. But as always, great video !
It would be similar that we calculate the difference of today's and y'day's price for all prices. The max profit would be the sum of all the profits (ignore the losses).
Master Data Structures & Algorithms for FREE at AlgoMap.io/
Theres also a really nice greedy solution to this also. Where it mentions 'You can buy it then immediately sell it on the same day.' Was something I overlooked at the start and wrote a solution like yours. Definitely worth noting to look for small bits of info like this in problems
My solution was this code :
profit = 0
for i in range(len(prices)-1):
diff = prices[i+1]-prices[i]
if diff>0:
profit += diff
return profit
No need to calculate low and high here.
But as always, great video !
Love your videos. Concise and easy to understand.
Love your video, it was concise, the solution was easy to understand and definitely helped me prepare for the interview, thanks :)
love this videos, very helpfull!.
Thank you!
extremely thorough and easy to understand! thank you for making these videos, im planning on binging your channel lolol
Binge it up at algomap.io :)
It would be similar that we calculate the difference of today's and y'day's price for all prices. The max profit would be the sum of all the profits (ignore the losses).
1:38 btw I am an intel employee
But you can buy and sell it the same day. So why don't we do it "scalping" way? make profit "day by day" ? It simplifies the aproach and it is fatser.
Intel lol 🤣🤣
Hahaha