Minimum swaps and K together 🔥🔥| Sliding Window | Array | Brute + Optimal Approach | C++

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • Time Stamps :
    Problem discussion : 0:00
    Brute force approach : 02:28
    Optimal approach : 04:15
    Dry Run Algorithm : 05:50
    Algorithm discussion : 09:31
    Code explanation : 11:07
    Time Complexity Discussion : 12:48
    Time Complexity : O(N)
    Space Complexity : O(1)
    Problem Link : practice.geeksforgeeks.org/pr...
    C++ Code Link : github.com/Ayu-99/Love-Babbar...
    Python Code Link: github.com/Ayu-99/Love-Babbar...
    Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
    Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)
    #DataStructuresAndAlgorithms
    #LoveBabbarDSASheet
    #interviewpreparation
    Minimum swaps and K together solution
    Minimum swaps and K together Leetcode
    Minimum swaps and K together C++
    Minimum swaps and K together C++ Hindi
    Minimum swaps and K together Hindi
    Checkout the series: 🔥🔥🔥
    👉 Array: • Arrays
    👉 Recursion : • Recursion
    👉 Stack and Queue : • Stack And Queue
    👉 Greedy : • Greedy
    👉 Dynamic Programming : • Dynamic Programming
    👉 Leetcode contests : • Leetcode contests
    👉 Leetcode June Challenge : • Leetcode June Challenge
    👉 Leetcode July Challenge : • Leetcode July Challenge
    LIKE | SHARE | SUBSCRIBE 🔥🔥😊

Komentáře • 55

  • @ayushidalal5488
    @ayushidalal5488 Před rokem +1

    Great explanation! I was able to write the code myself, thanks :)

  • @amanahirwar9236
    @amanahirwar9236 Před rokem +1

    thank you for the optimized solution and all the best for your future.

  • @soniamalik4929
    @soniamalik4929 Před 2 lety +6

    Di you teach soooo well.Blessed to get notified about your channel.Thank You!!

  • @prashantjain3959
    @prashantjain3959 Před 11 měsíci +1

    thanks for always proving for the best explanation

  • @parthkukkar7770
    @parthkukkar7770 Před rokem

    thanks a lot understood completely

  • @SonuKumar-uq2rb
    @SonuKumar-uq2rb Před 10 měsíci +1

    wow! the way of explaining is superb. keep it up sister.

  • @pushpendrapal8393
    @pushpendrapal8393 Před 9 měsíci

    You have explained very well

  • @jatinlanje5741
    @jatinlanje5741 Před rokem

    well explained!

  • @RiyaSingh-nj1fx
    @RiyaSingh-nj1fx Před 2 lety

    Waah waah kya khub samjhaya hai behen tumne....really appreciate

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

    Feels like yaad karke aayi hai

  • @neelesh621
    @neelesh621 Před 2 lety

    very well explained!!!

  • @hariaiyar1119
    @hariaiyar1119 Před 2 lety

    Great explanation

  • @pawankumarpandit1822
    @pawankumarpandit1822 Před rokem

    nice explanation mam

  • @harshsharma5066
    @harshsharma5066 Před 11 měsíci +1

    This question was asked in Josh Technolgy coding round but I was unable to solve it

  • @lalitbisht8381
    @lalitbisht8381 Před 3 měsíci

    Nice explanation

  • @ParmodYadav
    @ParmodYadav Před 10 měsíci

    Amazing Explanation Mam

  • @shivsagarshah24
    @shivsagarshah24 Před 2 lety

    nice explanation

  • @pawankumarpandit1822
    @pawankumarpandit1822 Před rokem

    i always watch you on black tshirt di...........

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

    Achha explain kiyaa thnx👍

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety

      Welcome. Glad it helped :). Please do share channel with your friends and juniors.

    • @ajit287
      @ajit287 Před 2 lety

      @@AyushiSharmaDSA Already shared...

    • @pratikbhange4780
      @pratikbhange4780 Před 2 lety

      @@AyushiSharmaDSA jii

  • @shaikfahim1232
    @shaikfahim1232 Před 2 lety +7

    didi,should we have to use j=count-1 or is it right as you mentioned above

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

      ya i too have the same doubt

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

      @@nvyashwin5512 same doubt

    • @pareekshithachar3788
      @pareekshithachar3788 Před rokem +2

      j = count, because we have already calculated for 0-count-1 initially, Now the for loop is deciding to add J and remove I, that is add the j= count element and remove i=0 element. Hope it helped

  • @vinaymaurya3038
    @vinaymaurya3038 Před 2 lety

    Nyc explanation

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

      Thank you :) glad it was helpful

    • @vinaymaurya3038
      @vinaymaurya3038 Před 2 lety

      @@AyushiSharmaDSA maam, u explained solution in simple way i hope it will help more students to understand this question.

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety

      @@vinaymaurya3038 thank you Vinay🙂

  • @anweshaaddya5459
    @anweshaaddya5459 Před rokem +1

    why is ++count and not ++count and also ++i and ++j instead of i++ and j++? could you pls explain

    • @ktprasanth007
      @ktprasanth007 Před 4 měsíci

      Anyways these are written as increment statements, they work the same way. In for loops the increment statements will be executed at the end of iteration

  • @srinivasmadupada4519
    @srinivasmadupada4519 Před rokem

    Can I use Dutch flag algorithm

  • @godisnoob675
    @godisnoob675 Před 2 lety

    i diidnt understand the last for loop , why j=count?

    • @tarunkumar.d8379
      @tarunkumar.d8379 Před rokem +1

      As we need to group all elements less than or equal to k together, we take the count of such numbers then create a window of that size, thats why j is initilized with count.

  • @thejavascriptworkmate8533

    Thanksu

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

    in third FOR loop ,shouldn't we start by i=1,j=count+1.Because we have solved this window in second for loop. ALSO IT COULD CAUSE ERROR AS IN THE SAME WINDOW I=0 TO J= COUNT ,WE ARE DOING OPERATION TWICE .Please reply ,may be i M WRONG.

    • @rubaborithm1911
      @rubaborithm1911 Před 2 lety

      ,FOR ex suppose we choose a window 6,7,2 .bad word =2 if k=3 in 2nd for loop .But when we come to third for loop since 6 at index=0 >3,we decrease bad word to 1 which is wrong i think

    • @viralchingaari2184
      @viralchingaari2184 Před 2 lety

      we have already calculated for index 0 to count-1 i.e 2 and in second we start i=0 and j=count(3) here i still has the prev value bcz it has to be excluded and j is already included if we start as i=1 then we would be excluding 1 but in this case we have to exclude 0 and j is already at 3 9

  • @tekbssync5727
    @tekbssync5727 Před 2 lety +2

    My code gives TLE in gfg , I have applied same concept as yours. [ What could be the reason for this TLE?]
    int minSwap(int *a, int n, int k) {
    int ans= INT_MAX;
    int cnt=0;
    for(int i=0; i

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

      This code doesn't give TLE if you add below corner cases for two conditions where no swaps are required
      and u should return 0 when u encounter any of the below:
      --> if(cnt==0 || cnt==n) return 0;
      1. When there are no elements less than or equal to k.
      2. If all the elements are less than or equal to k.

    • @tekbssync5727
      @tekbssync5727 Před 2 lety

      @@pavanabhishek2053 yeah its working now , thank you !!!

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

    ji how about, if u could explain in english?
    Saying because there are already many youtube channels following babbar sheet in hindi
    But no one in english