Increasing Triplet Subsequence | leetcode 334 | followup On Time O1 Space

Поделиться
HTML-код
  • Опубликовано: 19 ноя 2024

Комментарии • 64

  • @codelite700
    @codelite700 2 года назад +9

    Pre-compute left min and right max really opened my brain. Just WOW

  • @Account-fi1cu
    @Account-fi1cu 2 года назад +3

    I'm reading the comments and most people who complain probably didn't listen till the end of the video or paid any attention.
    You covered all important steps to tackle this problem, giving us 3 approaches from least efficient all the way to the optimized, preferred solution, THANK YOU !

  • @akshaychavan5511
    @akshaychavan5511 8 месяцев назад +1

    The idea is brilliant, but kind of slow.
    Here are two approaches -
    approach 1 -
    def increasingTriplet(self, nums: List[int]) -> bool:
    num1 = num2 = float('inf')
    for n in nums:
    if n leftMin[i] and nums[i]

  • @anirudhatalmale5575
    @anirudhatalmale5575 3 года назад +6

    nailed it .... awesome explanation from brute force to optimal

  • @NikhilKumar-od7qh
    @NikhilKumar-od7qh 2 года назад +6

    I think the test case [5,1,4,2,0,3] fails with the third approach because it gives true by considering triplet (0,2,3) while the actual triplet needed to be considered is (1,2,3)

  • @aayushpagare9366
    @aayushpagare9366 3 года назад +3

    I tried it using Longest Increasing Subsequence and got TLE 😂

  • @bhagavanprasad
    @bhagavanprasad Год назад

    Great solution,
    Definitely become awesome if handwriting slightly better

  • @arpitsatnalika
    @arpitsatnalika 3 года назад +3

    Amazing explanation

    • @NareshGupta
      @NareshGupta  3 года назад +1

      thanks and welcome to channel

  • @DonTaldo
    @DonTaldo 3 года назад +3

    Thanks for sharing! The content is pretty good but the sound isn't the greatest, I'd consider doing some investment over there since the content is very valuable

    • @NareshGupta
      @NareshGupta  3 года назад

      Thanks and Sorry for Soun Quality - Will take care from new videos.

    • @DonTaldo
      @DonTaldo 3 года назад

      @@NareshGupta Nothing to sorry about! Great content, keep on that :)!

  • @aneesbazmi1612
    @aneesbazmi1612 Год назад

    nums[i] != lm[i] and nums[i] != rm[i]

  • @Meenereem
    @Meenereem Год назад

    THANK YOU

  • @prasadm3614
    @prasadm3614 Год назад +1

    That second solution is wrong.... It fails for this kinda input 2,1,5,4,0,6

  • @adityan5302
    @adityan5302 2 года назад

    Nailed it !!! Loved your explanation !! :)

  • @guptapaaras
    @guptapaaras 11 месяцев назад +1

    Really poor explanation for the third approach. At least try to explain the intution rather than pre-compiled algorithm from leetcode.

  • @KundanKumar-im1gs
    @KundanKumar-im1gs 3 года назад

    but when i am trying to dry run the example that you have given....the value of first came out to be 2, second 6 and third 7, which will return true...but the order in question is not according to ans....how??

  • @shubhamchavan1387
    @shubhamchavan1387 3 года назад +1

    Thank you!!

  • @MennaTullahabdelrahman
    @MennaTullahabdelrahman Год назад

    Thanks that is create actually

  • @tanvishinde805
    @tanvishinde805 3 года назад +1

    how to come up with this line of thinking !

    • @JJ-qv8co
      @JJ-qv8co 3 года назад +1

      be a man

    • @bishwashkumarsah171
      @bishwashkumarsah171 2 года назад

      @@JJ-qv8co but she is a women she cannot change her gender now....u should have just said practice more and u will get the approach lol

    • @amaan6017
      @amaan6017 Год назад

      ​@@JJ-qv8co bhai ye kaisi baat keh rhe... ab koi iss cheez k liye gender kyun change krwaaye?

  • @sharuk3545
    @sharuk3545 3 года назад +2

    this is not O(1) SC bcz you take 2 extra arrays and its size depends on n there is no chance that we can say its O(1) SC

    • @NareshGupta
      @NareshGupta  3 года назад

      @Sharuk I think you missed second half of the video. In video two solution is covered once with with array (definitely O(n) space) and without array with constant variables that is O(1) space.

  • @adarshnegi4785
    @adarshnegi4785 Год назад

    [20,100,10,12,5,13]
    for test case. value of f finally becomes 5 , value of s beomes 12 , how it still returning true. i am stuck with this, even a little help will be appreiciated.

    • @swayambhunathan
      @swayambhunathan 10 месяцев назад

      because in next iteration both the if conditions for updating first and second values are skipped as 13 is not lesser than both values. but from previous updating of values we know we have two values updated in sequence and third one which is 13 is definitely bigger than last two updated numbers as both the numbers didn't get updated. so it goes to the else part and return true. I hope it makes sense.

    • @swayambhunathan
      @swayambhunathan 10 месяцев назад

      it doesn't matter how many times both the numbers are getting updated. what matters is whenever both the numbers are getting updated it is giving us a subsequence. so in any further iterations if both the numbers are not getting updated it automatically means next number is bigger.

    • @swayambhunathan
      @swayambhunathan 10 месяцев назад

      so the loop returning false will always happen when loop exhausted at updating first number.

  • @Ammar23217
    @Ammar23217 Год назад +2

    your solution is wrong because your space complexity is O(N) and the required in question is O(1)

  • @VivekGupta-mn7vy
    @VivekGupta-mn7vy 2 года назад

    thanks man!!

  • @AhmedSoliman-dk6pc
    @AhmedSoliman-dk6pc 8 месяцев назад

    Thanks

  • @payalsagar1808
    @payalsagar1808 3 года назад +1

    Wow😁

  • @prateekbansal2014
    @prateekbansal2014 2 года назад +1

    to the point explanation 🔥

  • @arpitvijay9382
    @arpitvijay9382 Год назад +1

    perfect video

  • @rohitanjane1668
    @rohitanjane1668 Год назад

    Best explanation Bro 🔥👍🏻

  • @sahilsaxena8374
    @sahilsaxena8374 3 года назад +1

    Sir this code will fails
    I tried on gfg
    Ex- 48,43,60,2,93
    Your output true
    But actual false.

    • @NareshGupta
      @NareshGupta  3 года назад

      Why you are thinking there is no incresing triplet subsequence in you input?

    • @sahilsaxena8374
      @sahilsaxena8374 3 года назад

      @@NareshGupta sir check on gfg
      It will give wrong answer

    • @sahilsaxena8374
      @sahilsaxena8374 3 года назад

      Or check my input case
      It will give wrong answer

    • @NareshGupta
      @NareshGupta  3 года назад

      @@sahilsaxena8374 This is not answer of my question.
      48,43,60,2,93 --> [48, 60 93], [43, 60, 93] ==> clearly two increasing triplet subsequence.

    • @sahilsaxena8374
      @sahilsaxena8374 3 года назад +2

      @@NareshGupta
      But sir value of i,j,k vo toh shi nhi h

  • @techmind9608
    @techmind9608 29 дней назад

    bhai, hindi mai kosis krlo

  • @gunjanagrawal6032
    @gunjanagrawal6032 3 года назад +1

    really POOR explanation for 3rd approach

    • @NareshGupta
      @NareshGupta  3 года назад

      May, I know what was not clear in that so that I can take care on that part?

    • @ankitdas6009
      @ankitdas6009 3 года назад

      @@NareshGupta At last, when you were explaining how we got an increasing triplet subsequence, I mean when f became 0.

  • @khushable
    @khushable 3 года назад +1

    Awesome explanation