Row with max 1's | Naive-Better-Best Approach | Matrix | Interview Question

Sdílet
Vložit
  • čas přidán 14. 11. 2020
  • In this video I have explained the solution for row with max 1's starting from Naive to Optimal Approach.
    DO LIKE AND SHARE THIS VIDEO AND DON'T FORGET TO SUBSCRIBE !!
    C++:- github.com/tejasbirsingh/Prog...

Komentáře • 32

  • @ayushidalal5488
    @ayushidalal5488 Před rokem

    nicely explained

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

    Great Explanation 👏

  • @barshapal_1227
    @barshapal_1227 Před 3 lety +1

    superb

  • @dharanyuvi6951
    @dharanyuvi6951 Před 2 lety

    wonderful presentation

  • @madhav3444
    @madhav3444 Před 3 lety

    Great explanation. Thanks brother

  • @gurmukhsinghnirman4935

    Awesome explanation👌👌

  • @AddiNarayan
    @AddiNarayan Před 2 lety

    Great explanation

  • @AmanKumar-kz1rn
    @AmanKumar-kz1rn Před 3 lety +1

    thanks buddy good explanation keep making videos

  • @ankitkumarmahato4318
    @ankitkumarmahato4318 Před 3 lety +1

    I also thought the same naive approach(except i initialized row=-1), i thought it will show tle but it failed in one of the cases.

  • @abhishekgupta3698
    @abhishekgupta3698 Před 3 lety +1

    Thanks brother

  • @ankitdubey9310
    @ankitdubey9310 Před 3 lety

    hello bro we have to return the first instance of max 1's the code you wrote shows the latest instance of the code, please help me with that

  • @rohandevaki4349
    @rohandevaki4349 Před 2 lety

    at 13:41 , for column if worst case is that all rows have 0 and only one column and one row has 1 (bottom right and bottom left)
    then you traverse each row and column , so it is also o(N*M) right?

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

    What if 1st row has all 0 with no 1...then your code must b wrong

  • @sachintendulkar6951
    @sachintendulkar6951 Před 3 lety

    But I think binary search on everyrow works it takes less tiem

  • @shivangisharma3643
    @shivangisharma3643 Před 3 lety

    When I m submitting my code it is showing your code failed for multiple testcases. please help

  • @madhav3444
    @madhav3444 Před 3 lety

    Bro optimal 1 solution is giving wrong answer in one case where N=1000 and M=1000 , It's correct ouput is 976 but code is giving 0 answer. Don't know why ?

  • @mayankverma2356
    @mayankverma2356 Před 3 lety +1

    how O(n+m) is best approach ???
    best will be O(log(m))

    • @ClashingCoder
      @ClashingCoder  Před 3 lety +1

      Using Binary search will be O(Logn) which will be applied on each row therefore total time will be O(totalRows Log (totalCols)) whereas Pointers approach will take O(n + m ) time which is less than n log m.

    • @SHASHANKRUSTAGII
      @SHASHANKRUSTAGII Před 3 lety

      @@ClashingCoder
      int rowWithMax1s(vector a, int n, int m)
      {
      int res=-1;
      for(int i=0;i

  • @lokeshnegi5051
    @lokeshnegi5051 Před 3 lety

    your explanation is good but try to reduce the pace.

    • @ClashingCoder
      @ClashingCoder  Před 3 lety

      Yea I have got feedback from many viewers on that. In new video I will improve that. Thanks!

  • @rishabsharma5307
    @rishabsharma5307 Před 3 lety +1

    Can you explain why the TC of optimal solution is O(N + M)

    • @insane2539
      @insane2539 Před 2 lety

      because you travelling m horizontal steps and n vertical steps to traverse the complete array in worst case therefore O(n+m)

  • @mikegaming7160
    @mikegaming7160 Před 3 lety

    bro what will be the answer for test case 3 3 -----> 0 1 1 1 0 0 0 0 0

    • @ClashingCoder
      @ClashingCoder  Před 3 lety

      This will not be a valid input this question as in a row there can't be 0s after 1. For the input provided by you this algorithm will output 1 as answer as per 0 based indexing. So this answer will be wrong in sense of maximum 1's per row

  • @sanyamgoel1259
    @sanyamgoel1259 Před 3 lety

    Confusing, sorry but it' is truth.

    • @ClashingCoder
      @ClashingCoder  Před 3 lety

      I will try to improve video quality and explain properly. Thanks for pointing out the problem!

  • @shubhayanai8981
    @shubhayanai8981 Před 3 lety

    Most Simple Solution based on the logic
    int row=m;
    int pos=-1;
    for (int i=0;i