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

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 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)

    • @kuntasunny8688
      @kuntasunny8688 2 ปีที่แล้ว +2

      yes third approach doesn't work

    • @kushagarsharma4783
      @kushagarsharma4783 6 หลายเดือนก่อน +2

      Yup it also fails for 2,1,5,0,0,6

  • @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

  • @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 :)!

  • @arpitsatnalika
    @arpitsatnalika 3 ปีที่แล้ว +3

    Amazing explanation

    • @NareshGupta
      @NareshGupta  3 ปีที่แล้ว +1

      thanks and welcome to channel

  • @prasadm3614
    @prasadm3614 ปีที่แล้ว +1

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

  • @aneesbazmi1612
    @aneesbazmi1612 ปีที่แล้ว

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

  • @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??

  • @adityan5302
    @adityan5302 2 ปีที่แล้ว

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

  • @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.

  • @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?

  • @Meenereem
    @Meenereem ปีที่แล้ว

    THANK YOU

  • @MennaTullahabdelrahman
    @MennaTullahabdelrahman ปีที่แล้ว

    Thanks that is create actually

  • @shubhamchavan1387
    @shubhamchavan1387 3 ปีที่แล้ว +1

    Thank you!!

  • @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.

  • @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.

  • @VivekGupta-mn7vy
    @VivekGupta-mn7vy 2 ปีที่แล้ว

    thanks man!!

  • @AhmedSoliman-dk6pc
    @AhmedSoliman-dk6pc 8 หลายเดือนก่อน

    Thanks

    • @NareshGupta
      @NareshGupta  8 หลายเดือนก่อน +1

      Welcome

  • @payalsagar1808
    @payalsagar1808 3 ปีที่แล้ว +1

    Wow😁

  • @prateekbansal2014
    @prateekbansal2014 2 ปีที่แล้ว +1

    to the point explanation 🔥

  • @rohitanjane1668
    @rohitanjane1668 ปีที่แล้ว

    Best explanation Bro 🔥👍🏻

  • @arpitvijay9382
    @arpitvijay9382 ปีที่แล้ว +1

    perfect video

  • @Ammar23217
    @Ammar23217 ปีที่แล้ว +2

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

  • @techmind9608
    @techmind9608 หลายเดือนก่อน

    bhai, hindi mai kosis krlo

  • @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

  • @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