Continuous Subarrays | Leetcode 2762

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

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

  • @sivapradeep977
    @sivapradeep977 19 часов назад +19

    Suddenly my brain is not braining😂😂

    • @techdose4u
      @techdose4u  15 часов назад +1

      This is funniest 🤣

  • @rutikbhanushali957
    @rutikbhanushali957 15 часов назад +9

    Moving left pointer back to avoid duplicate was a bit tricky...

  • @Anikait-h3d
    @Anikait-h3d 13 часов назад +6

    Loving the explanation Hating the problem

    • @techdose4u
      @techdose4u  13 часов назад

      hahahaaha 🤣

    • @heybeachMIN
      @heybeachMIN 2 часа назад +1

      @@techdose4u Hi, your python code is not right. There is a small error there, at the end after the loop "for" you need to add to win_size + 1, that is, win_size = r - l + 1. I'm not exactly sure, but maybe this is because we don't add to the count without the condition max - min > 2 and always in the end we need to add to count and there the count in the loop starts from zero, so + 1. Sry for engl)

    • @techdose4u
      @techdose4u  2 часа назад

      yea.
      AI is trash 😮‍💨

  • @ishanbhatt6067
    @ishanbhatt6067 Час назад

    great call to include the complexity analysis! i came up with a similar solution but rejected it because i thought moving left pointer back would cause the complexity to become N-squared!
    thanks :)

  • @MP-ny3ep
    @MP-ny3ep 19 часов назад

    Very beautifully explained !

  • @smitshah2113
    @smitshah2113 5 часов назад

    Nice explanation. Thanks. Just one tiny bug: when moving back left, we need to ensure we are not moving out of the array

    • @techdose4u
      @techdose4u  4 часа назад

      but that condition wont arise coz we must have a break point otherwise the right pointer wouldnt stop!

    • @smitshah2113
      @smitshah2113 3 часа назад

      @@techdose4u Ah, yes... the fact that the right pointer did stop means that there are two indices for which the subarray is not continuous. Hence we would stop moving left before going out of bounds. Thanks :)

    • @techdose4u
      @techdose4u  3 часа назад

      yep :)

  • @freecourseplatformenglish2829
    @freecourseplatformenglish2829 7 часов назад

    Excellent expalination, I too comeup with the exact approach but struggle to code it. Thanks man.

  • @asgarantony
    @asgarantony 9 часов назад

    Good explanation Sir.

  • @jaatharsh
    @jaatharsh 11 часов назад

    good explanation as always, many thanks

  • @ujjwal_7531
    @ujjwal_7531 7 часов назад

    wonderful explain

  • @BigStin-0
    @BigStin-0 21 час назад +3

    God damn, my head hurts hahaha

    • @techdose4u
      @techdose4u  20 часов назад +2

      🤣 brain teaser 🧠

  • @algorithmsanddatastructure3701
    @algorithmsanddatastructure3701 16 часов назад

    i think we can adjust the left pointer also simply by maintaining the index and updating the index if the same number occuring multiple times

    • @techdose4u
      @techdose4u  15 часов назад

      yes.
      But the candidates may differ and so you will endup maintaining all frequencies :)

    • @algorithmsanddatastructure3701
      @algorithmsanddatastructure3701 12 часов назад

      @techdose4u i am thinking of maintaining the index of only max and min,so whenever difference is greater than the given number, it will be because max and min, so accordingly we can move the left pointer either to min or max which ever was present in the subarray

  • @nicolaswolyniec1354
    @nicolaswolyniec1354 9 часов назад +1

    the python solution will give you a wrong answer. After finishing the loop, you can not use the right variable because the value is n-1
    win_size = len(nums) - left
    count += (win_size * (win_size + 1)) // 2

  • @gireeswar18
    @gireeswar18 19 часов назад +1

    Nice explanation, may I know which blackboard you are using?

  • @Abhishek-e6d2c
    @Abhishek-e6d2c 17 часов назад

    what an explanation!!!

  • @lakithakare7387
    @lakithakare7387 16 часов назад

    Thank you

  • @devmahad
    @devmahad 5 часов назад

    thanks :)

  • @vidhyarthisunav
    @vidhyarthisunav 11 часов назад

    Your Python code in the link need minor enhancement. n = len(nums) should be used instead of right pointer to calculate the final number of subarrays to be addes outside the loop on line number 126. It should be win_size = n - left instead of win_size = right - left.

  • @dieformusic1705
    @dieformusic1705 18 часов назад

    sir can i use priority queues to maintain min and max values so as to avoid the left movement of L pointer where i can update L pointer to the index choosen from the priority queues after checking the condition?

    • @techdose4u
      @techdose4u  15 часов назад

      Yea you can take priority queue but you will need 2 heaps. One for min and one for max

  • @vishalgadade1585
    @vishalgadade1585 20 часов назад

    As you are moving pointer again to left when we found any fault
    Isn't it is disturbing cpu cycle? Because it is making knot of pointers during computation
    Can we optimize this knot ?

    • @techdose4u
      @techdose4u  20 часов назад

      can you please explain with an example

  • @SzrIsTaken786
    @SzrIsTaken786 21 час назад

    Had the sliding window part down, the maximum and minimum threw me off a bit but the formula is the part where I'm thinking "how the heck??"

    • @techdose4u
      @techdose4u  20 часов назад +1

      yea, it was not your daily sliding window :o confusing

  • @pravyn350
    @pravyn350 14 часов назад

    This guy ❤

  • @LinhHoang-ml1qo
    @LinhHoang-ml1qo 6 часов назад

    Hi sir, I think exactly the time complexity is O(2N) in the worst case l and r is both come to the last of index. Please confirm if my comment is false.Thank you so much and have a good day

    • @techdose4u
      @techdose4u  4 часа назад

      Anything is O(N)
      Thankfully we dont need to consider constants :)

  • @firstyfirst
    @firstyfirst 13 часов назад

    would maintaining a index whenever I update max help last wala update will be stored and my next L would be ind+1;

    • @techdose4u
      @techdose4u  13 часов назад

      The max may not be optimal.
      ex. 8,7,1
      repeatLimit: 2
      Last max will give 8 but you needed 7 :)

  • @vikasvoruganti7490
    @vikasvoruganti7490 17 часов назад

    Time to practice more sliding window problems 😢

    • @techdose4u
      @techdose4u  15 часов назад

      but this was an outlier :)

  • @sailendrachettri8521
    @sailendrachettri8521 9 часов назад

    And i was just counting subarrays

    • @techdose4u
      @techdose4u  8 часов назад

      Need to subtract the redundant ones :)

  • @B-Billy
    @B-Billy 17 часов назад +1

    I was with you until you start talking about moving L pointer.

    • @techdose4u
      @techdose4u  15 часов назад

      You can rewatch and do dry run on examples to clear :)

  • @thetruebluesingaporeankid
    @thetruebluesingaporeankid 17 часов назад

    could explain why the n*(n+1)/2 come about?

    • @techdose4u
      @techdose4u  15 часов назад

      You can enumerate and count.
      it will be this always:)

  • @nileshbhanot2776
    @nileshbhanot2776 18 часов назад

    Your python does not submit on leetcode and provides wrong output. Kindly, please check

    • @techdose4u
      @techdose4u  15 часов назад

      omg
      How can AI take jobs if they can’t even convert codes 🥹

    • @satguy8481
      @satguy8481 14 часов назад

      @nileshbhanot2776 betaa khud se code likh le cheating krne aa gya moo utha ker. Approach dekh code nhi

  • @AKProductionsTelugu
    @AKProductionsTelugu 9 часов назад

    why don't you move the left pointer to right man its striaght forward and less complicated for explaining!

  • @eliomorningstar7392
    @eliomorningstar7392 19 часов назад +1

    sir is it possible if you can explain the segment or fenwick tree approach for this problem?

    • @techdose4u
      @techdose4u  19 часов назад +3

      that will be overkill.
      Nothing better than 2 pointer.
      currently I am focusing on easy and optimal solutions.
      Overkill is not recommended :)

  • @AlbinSabu-y2v
    @AlbinSabu-y2v 18 часов назад +1

    This is first time I see the window is going like a swing. That made me confusing(especially the double count & subtracton🥲). If I had never seen this algo my dumb brain could never figure out the soln.

    • @techdose4u
      @techdose4u  15 часов назад

      This was an outlier so cant blame anyone!