Leetcode 122. Best Time to Buy and Sell Stock II

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 26

  • @unknownuser8912
    @unknownuser8912 Před 2 lety +5

    I am a beginner and I used the greedy approach but didn't know it was called greedy approach. Thanks !!

  • @aayushagrawal7999
    @aayushagrawal7999 Před rokem +1

    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.

  • @gautambnsl
    @gautambnsl Před 3 lety +2

    Thankyou! Helpful Video.

  • @kirtisingh7252
    @kirtisingh7252 Před rokem

    Thank you Fraz , you explained it so well.

  • @OnePunchSaga
    @OnePunchSaga Před 3 lety +1

    thank you for the amazing video

  • @dheerjain2884
    @dheerjain2884 Před 3 lety +2

    Beautifully explained!!!

  • @AshishSingh-ez8tn
    @AshishSingh-ez8tn Před 2 lety

    U explained it so well..thankuu

  • @dheerjain2884
    @dheerjain2884 Před 3 lety +2

    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?

    • @mohammadfraz
      @mohammadfraz  Před 3 lety +1

      Interviewers expect the greedy way as well

  • @ratnasanjay
    @ratnasanjay Před 2 lety

    Thankyou bhaiya for this session

  • @ruhinapatel6530
    @ruhinapatel6530 Před 2 lety

    Very good solution

  • @siddharthmehta4223
    @siddharthmehta4223 Před 2 lety +1

    fucking awesome

  • @shivarajhalageri2513
    @shivarajhalageri2513 Před 3 lety +1

    What about i-1th element of the array, for the first element

  • @abhiimali
    @abhiimali Před 2 lety

    thank you 💗

  • @mohdsaadalikhan7209
    @mohdsaadalikhan7209 Před 3 lety

    nice explanation

  • @renukach7927
    @renukach7927 Před rokem

    @Fraz Which editor are you using?

  • @srinish1993
    @srinish1993 Před 2 lety

    public int maxProfit(int[] prices) {
    int profit = 0;
    for(int i=1; i

  • @mihirit7137
    @mihirit7137 Před 2 lety

    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 ?

    • @mathimagery
      @mathimagery Před 7 měsíci

      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

  • @ruhinapatel6530
    @ruhinapatel6530 Před 2 lety

    This is kadane's algo..

  • @amanahmed6057
    @amanahmed6057 Před 3 lety

    bhai sheet ke saare question par banaao plzzzzzzzzzzzz bhai

  • @KishanKumar-zi5dp
    @KishanKumar-zi5dp Před 2 lety

    Plzz provide java solution..

    • @N451M4K
      @N451M4K Před rokem +1

      class Solution {
      public int maxProfit(int[] prices) {
      int net_profit=0;
      for(int i=1; i