While solving question i thought the solution might be very big and complex ,but to my surprise it was 'opposite'. Thank you fraz for such an amazing soln.
Hey, so I tried this problem from the DSA Sheet. I was able to come up with a solution in O(n) Time, O(1) Space using dynamic programming. Do I save it for round2 of the sheet(if i did not come up with a greedy approach but time complexity and space is optimal)? My main doubt is that: if I am able to come up with most optimal approach in terms of time and space (DP) but there exists another approach(greedy in this case) with same performance, Should I chop out of the sum from the sheet or keep it for round2?
i=0 profit=0 N=(len(prices))-1 while(iprices[i]: profit=profit+prices[i+1]-prices[i] return profit i tried to code this logic in python however it isnt exceuting could someone help why ?
I am a beginner and I used the greedy approach but didn't know it was called greedy approach. Thanks !!
While solving question i thought the solution might be very big and complex ,but to my surprise it was 'opposite'. Thank you fraz for such an amazing soln.
Thankyou! Helpful Video.
Thanks ☺️
Thank you Fraz , you explained it so well.
thank you for the amazing video
Beautifully explained!!!
Thanks bro
@@mohammadfraz +1
U explained it so well..thankuu
Hey, so I tried this problem from the DSA Sheet. I was able to come up with a solution in O(n) Time, O(1) Space using dynamic programming. Do I save it for round2 of the sheet(if i did not come up with a greedy approach but time complexity and space is optimal)? My main doubt is that: if I am able to come up with most optimal approach in terms of time and space (DP) but there exists another approach(greedy in this case) with same performance, Should I chop out of the sum from the sheet or keep it for round2?
Interviewers expect the greedy way as well
Thankyou bhaiya for this session
Very good solution
fucking awesome
What about i-1th element of the array, for the first element
thank you 💗
nice explanation
@Fraz Which editor are you using?
public int maxProfit(int[] prices) {
int profit = 0;
for(int i=1; i
i=0
profit=0
N=(len(prices))-1
while(iprices[i]:
profit=profit+prices[i+1]-prices[i]
return profit
i tried to code this logic in python however it isnt exceuting could someone help why ?
net_profit = 0
for idx in range(1, len(prices)):
if prices[idx] > prices[idx-1]:
net_profit += prices[idx] - prices[idx-1]
return net_profit
This is kadane's algo..
bhai sheet ke saare question par banaao plzzzzzzzzzzzz bhai
Plzz provide java solution..
class Solution {
public int maxProfit(int[] prices) {
int net_profit=0;
for(int i=1; i