Maximum Ones after Modification InterviewBit Code + Examples C++

Sdílet
Vložit
  • čas přidán 20. 08. 2024
  • Given a binary array A and a number B, we need to find length of the longest subsegment of ‘1’s possible by changing at most B ‘0’s.
    A[i]=0 or A[i]=1
    Input Format
    First argument is an binary array A.
    Second argument is an integer B.
    Output Format
    Return a single integer denoting the length of the longest subsegment of ‘1’s possible by changing at most B ‘0’s.
    Example Input
    Input 1:
    A = [1, 0, 0, 1, 1, 0, 1]
    B = 1
    Input 2:
    A = [1, 0, 0, 1, 0, 1, 0, 1, 0, 1]
    B = 2

Komentáře • 33

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

    I don't why she is not that famous....her explanation is way better than every famous youtuber...

  • @utkarshasingh1836
    @utkarshasingh1836 Před rokem +4

    couldn't stop myself from commenting, you explained it with such simplicity and clarity.

  • @11iqra
    @11iqra Před rokem +3

    Best explanation of the problem on the internet!

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

    Thanks for the solution! I solved this with a little bit different approach.
    1. keep left and right at the start of the string
    2. initialize ones_freq = 0 and result = 0
    3. increment right by 1 and check if current character is 1, if yes increment ones_freq by 1
    4. while right-left+1 - ones_freq > B (current window has more zeros than we can flip)
    4.1 increment left by 1 (shrink window) if A[left] == 1 decrement ones_freq by 1
    5. Here we have window satisfying the criteria so take max(result, right-left+ 1)
    This approach is basically keeping count of 1 in window and based on difference == allowed flips it is calculating the max size

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

    Crystal clear explanation as always 🙇‍♂🙇‍♂

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

    just do it by using Sliding window concept
    int Solution::solve(vector &A, int B) {
    int count=B;
    int left=0;
    int right=0;
    int n= A.size();
    int maxLen=0;
    while(right=0)
    {
    count--;

    }
    if(count>=0)
    {
    maxLen= max(maxLen,right-left+1);
    }
    while(count

  • @ravitalaugh9017
    @ravitalaugh9017 Před 5 měsíci

    your explanation is really good

  • @LearnWithAnmolll
    @LearnWithAnmolll Před měsícem +1

    great explanation !!!!

  • @AjayKushwaha-vi5vg
    @AjayKushwaha-vi5vg Před rokem +1

    superb clear explanation.

  • @feelit5386
    @feelit5386 Před rokem

    truly amazing, aab nahi bhulunga yeh wala concept🥰

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

    great explanation .. keep posting .I just love it

  • @manojkr7554
    @manojkr7554 Před rokem +1

    Wow what a great explanation I love u dear ❤️💗🥰

  • @luckydewangan5985
    @luckydewangan5985 Před rokem

    best explation I got for this question here thankyou so much for this content

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

    Nice explanation

  • @anmolchauhan3822
    @anmolchauhan3822 Před rokem

    Very Nice Explanation Mam😄😄

  • @AdityaYadav-kf4uc
    @AdityaYadav-kf4uc Před rokem

    never commented on any youtube video but this explanation madee me to, thanks

  • @ankushladani496
    @ankushladani496 Před rokem

    Explained so easily....

  • @notyet5009
    @notyet5009 Před rokem +1

    Special thanks to alisha's brother who is unable to sleep bcz of these lectures.

  • @lostcyrus8578
    @lostcyrus8578 Před rokem

    Good explanation keep it up

    • @lostcyrus8578
      @lostcyrus8578 Před rokem

      Please make more videos on popular questions.. you can refer to striver SDE sheet medium and hard ones

  • @darkexodus6404
    @darkexodus6404 Před rokem

    After watching first 10mins of your video, this is how I tried to implemented it. My thought process was like to maintain a window.
    int findZeroes(int arr[], int n, int m) {
    vector zeros;
    for(int i=0; i

  • @saikrishna872
    @saikrishna872 Před rokem

    Good Explanation What is Time and Space complexity

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

    mam could we also do it by recursion by thinking to either include one zero or not and then calculating maximum calculating for that choice

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

    Nice explanation, also in order to develop the intuition to solve problems is there any way? Or is this just practice, like solve n number of problems so that if n+1 problem is similar to any problem in those n just think similarly?

  • @SaTyamRaWaTvloGs
    @SaTyamRaWaTvloGs Před rokem

    💯

  • @abhishekanand9430
    @abhishekanand9430 Před rokem

    complixity will be greater than n

  • @collegematerial5348
    @collegematerial5348 Před rokem

    Why you minus for calculate length

  • @rahulgheware5752
    @rahulgheware5752 Před rokem

    By using queue it is possible to store previous zero

  • @rishabhsingh-gw3gf
    @rishabhsingh-gw3gf Před 11 měsíci

    woh bnda peeche so raha hai mooh par takiya laga kar🤣🤣

  • @abhishekkarn8918
    @abhishekkarn8918 Před 2 lety

    whats the time complexity

  • @nostalgiccringeallhailchel3881

    weird explaination. Would have been much easier to understand if you just said you were gonna use sliding point approach