Flip

Sdílet
Vložit
  • čas přidán 28. 07. 2024
  • Timestamps:
    0:00 Reading the problem
    2:30 Explaining intuition
    3:30 Kadane Algorithm
    6:00 Kadane Code and Dry Run
    10:30 Example dry run
    13:02 Code CPP
    Input Format
    First and only argument is a string A.
    Output Format
    Return an array of integers denoting the answer.
    Example Input
    Input 1:
    A = "010"
    Input 2:
    A = "111"
    Example Output
    Output 1:
    [1, 1]
    Output 2:
    []
    Example Explanation
    Explanation 1:
    A = "010"
    Pair of [L, R] | Final string
    ___________|_________
    [1 1] | "110"
    [1 2] | "100"
    [1 3] | "101"
    [2 2] | "000"
    [2 3] | "001"
    We see that two pairs [1, 1] and [1, 3] give same number of 1s in final string. So, we return [1, 1].
    Explanation 2:
    No operation can give us more than three 1s in final string. So, we return empty array [].

Komentáře • 33

  • @avinashvishwakarma6488
    @avinashvishwakarma6488 Před 2 lety +11

    The best part about your explanation is that you always develop the intuition first. That helps me a lot in solving other similar problems. Keep making more videos of interviewbit problems. Thanks a lot.

  • @manikmalhotra3903
    @manikmalhotra3903 Před 2 lety +4

    Just came across this channel. One of the best and easy-to-understand content. Thank you

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

    Really loved the way you have explained the concept and related the two problems.

  • @annanyamathur8869
    @annanyamathur8869 Před 2 lety

    I really like your way of explaining

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

    Tysm mam, it was great, loved it, big fan of u mam

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

    Top notch explanation. Thank you for existing

  • @raj_kundalia
    @raj_kundalia Před 2 lety

    Thanks for the video!

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

    thanks for the approach, I understand the concept clearly, but one thing I want to say is that changing input may not be feasible always, so it's better to keep a variable which ++ and -- accordingly.

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

    nice explanation(intution part)

  • @namanagrawal1908
    @namanagrawal1908 Před rokem

    Great Explanation

  • @vikaskumar-kc4jv
    @vikaskumar-kc4jv Před 2 lety +1

    Make more videos you are really awesome

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

    fantastic !!

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

    Hey Alisha Plz tell the way how to remember ,truth table of all flip flops quite confusing

  • @akashnigam5321
    @akashnigam5321 Před rokem

    Just got to know that you are an alumni of my college IIT Bombay, your videos are really helpful.

  • @truptisatsangi6043
    @truptisatsangi6043 Před 2 lety

    very nice explaination along with related topic so you to go nowhere for 1 question.
    Great job

  • @rithikrk3695
    @rithikrk3695 Před 8 měsíci

    Beauty with brain....very nice explanation mam!

  • @pharmacybyanuj2459
    @pharmacybyanuj2459 Před 2 lety

    your way of teaching is really superb when ever i understand any problem by you it clear my concepts.
    thanks Alisha didi
    di can you tell me how should i make dsa notes ? or make a video how to make dsa notes

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

    I guess you skip this part "return the lexicographically smallest pair of L and R."

    • @avinashvishwakarma6488
      @avinashvishwakarma6488 Před 2 lety

      but code still runs. Why?

    • @dishantmeena1621
      @dishantmeena1621 Před 2 lety

      Actually in this approach, we are considering only the best flipping which will give us the maximum no. of ones. So, we are constantly updating our L and R values and only return the best pos.
      Hope this will help.

  • @siddharthjain4361
    @siddharthjain4361 Před rokem

    hi , answer could be one or more right ...how did u check lexicographically for the same

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

    for java users -
    public static int[] flip(String A) {
    int left = -1, right = -1;
    int sum = 0, maxSum = 0, currleft = 0;
    for (int i = 0; i < A.length(); i++) {
    sum += A.charAt(i) == '0' ? 1 : -1;
    if (sum < 0) {
    sum = 0;
    currleft = i + 1;
    }
    if (sum > maxSum) {
    maxSum = sum;
    left = currleft;
    right = i;
    }
    }
    if (left == -1 && right == -1) return new int[0];
    return new int[]{left + 1, right + 1};
    }

  • @deepakkapasia1
    @deepakkapasia1 Před rokem

    More than half test cases failed with this solution. Explaination good for the question and kadane algo but figuring out index not explained.

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

    can u plzz share your code

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

    At the timestamp 7:22 in the kadane algorighm. the solution will not work for all the negative integer array.
    For example if the array is {-2,-4,-9,-3,-1}
    The maximum subarray sum will be -1. But with the above pseudo code, it will be 0.

  • @chandraprakashsahu8557

    can you please drop your linkedIn id

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

    hi mam I wanna Connect With you can i get your LinkedIn ID