HackerRank - Equal | Full Solution with Simplified Examples and Visuals | Study Algorithms

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

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

  • @doingsneakypeakylike
    @doingsneakypeakylike 3 года назад +5

    Thanks brother! Finally I understood it. The visuals and explanation were really good.

  • @sudarshanmaskare3328
    @sudarshanmaskare3328 Год назад +2

    Nice solution, we can have only three possibilites[ (min-0),(min-1),(min-2)],,,,,(min-5) will lead to recurrence.... Why? because in question we are given [1,2,5]...
    This works for me->
    int equal(vector arr) {
    vector possibilities(3);
    // Start with the minimum element
    int minimum = *min_element(arr.begin(),arr.end());
    for (int i = 0; i < 3; i++) {
    for (int k : arr) {
    int diff = k - minimum;
    int stepsRequired = diff / 5 + (diff % 5) / 2 + ((diff % 5) % 2) / 1;
    possibilities[i] += stepsRequired;
    }
    minimum--;
    }
    // Return the minimum number out of all the possibilities
    return *min_element(possibilities.begin(),possibilities.end());
    }

  • @praveenmani5672
    @praveenmani5672 7 месяцев назад +2

    Bro, Thanks a lot, finally understood the solution

  • @srinjaykapri7
    @srinjaykapri7 3 года назад +1

    voice(not so quick not so slow moderate)& explanation are on 🔥

  • @ajaysubramaniam4453
    @ajaysubramaniam4453 9 месяцев назад +1

    well explained.

  • @rajeshpaithari7320
    @rajeshpaithari7320 7 месяцев назад +1

    Heya, I'm still confused about min to min-4.

  • @artistic__08
    @artistic__08 Год назад +1

    My first thought was solving this through BFS

  • @kartika9415
    @kartika9415 3 года назад +1

    Great Work !!!!

  • @radhakalyaninakka5877
    @radhakalyaninakka5877 2 года назад +1

    very interesting explanation

  • @markohy9samy565
    @markohy9samy565 Год назад

    great explaination Thx alot !

  • @PIYUSH61004
    @PIYUSH61004 2 года назад +2

    Please explain more about the optimal solution being present in [min, min-4] range

    • @nikoo28
      @nikoo28  2 года назад +4

      The range comes from the fact that you can either give 1, 2 or 5 chocolates. That's why you have to check all the possibilities in that range. We do not go past "min-4" because that will take 5 operations which is same as a single operation of giving 5 chocolates at once.
      Hope that helps.

    • @PIYUSH61004
      @PIYUSH61004 2 года назад

      @@nikoo28 Finally I understood.. Thanks a lot, brother!

  • @vtmcedxc2573
    @vtmcedxc2573 3 года назад

    your explanation was great, it really helped me

  • @lahiruweliwitiya1
    @lahiruweliwitiya1 2 года назад

    Thank you for this explanation!

  • @jorgegonzaloalfaro5378
    @jorgegonzaloalfaro5378 3 года назад +1

    wow this was really good thank you!!!

  • @urbancoder96
    @urbancoder96 Год назад

    That is genius!

  • @tanishqmahendrasaini3764
    @tanishqmahendrasaini3764 3 года назад

    Very nice bro 😃 Well explained & animation made it so easy
    Thank You!!

  • @ayabc4320
    @ayabc4320 3 года назад +1

    Great video :) 😊

  • @sculptandstyle_
    @sculptandstyle_ 2 года назад +2

    i don't understand why only till min-4 is considered

  • @kumarisuruchisuman8919
    @kumarisuruchisuman8919 3 года назад

    what a explanation man

  • @aakashkatiyar5005
    @aakashkatiyar5005 3 года назад

    Very helpful!!

  • @rohanjain4238
    @rohanjain4238 2 года назад

    very detailed explanations

  • @alakmarshafin9065
    @alakmarshafin9065 3 года назад

    Nicely explained

  • @vijaykumarsingh5862
    @vijaykumarsingh5862 3 года назад +3

    how you come to know that min will go till min-4??

    • @nikoo28
      @nikoo28  3 года назад +4

      That is because she can give a maximum of 5 chocolates. If she was able to give 8 chocolates, then you would have to check till 7.

    • @aakrandan
      @aakrandan 3 года назад

      @@nikoo28 This is a vital information, should have mentioned in the description.

    • @nikoo28
      @nikoo28  3 года назад +1

      @@aakrandan This information is mentioned in the problem description. :)

    • @manojkalyan94
      @manojkalyan94 Год назад

      @@nikoo28 No where mentioned max of 5 chocolates can be distributed in pblm statement I have checked it

  • @siddhigolatkar8558
    @siddhigolatkar8558 3 года назад

    Thank you

  • @doremifasolatee6258
    @doremifasolatee6258 7 месяцев назад

    14:05 can someone please explain to me how is (minimum - 5) the same scenario??

    • @nikoo28
      @nikoo28  7 месяцев назад

      it is like dividing in groups of 5. the scenario will be same if it is 30 or 25 or 35

    • @hoddybhaba6704
      @hoddybhaba6704 Месяц назад

      I had the same doubt on watching this video…

  • @shwetaravi2696
    @shwetaravi2696 3 года назад

    bruh i have a doubt what if min=2,then will the still continue till it calculates min-4

    • @nikoo28
      @nikoo28  3 года назад

      yes…you need to calculate every possible min. Otherwise how will you know that min =2?

  • @BestOption19
    @BestOption19 3 года назад

    when we reach min-5 then how it will be same scenario ??(14:02)

    • @nikoo28
      @nikoo28  3 года назад +1

      If you reach ‘min-5’, then you will reach the same scenario you started with.
      Try to do a dry run and take away 5 chocolates, you will find yourself in a recurrence :)

  • @hoddybhaba6704
    @hoddybhaba6704 Месяц назад

    Don’t understand the Min to min -4 logic

  • @uttamkumarreddygaggenapall2504
    @uttamkumarreddygaggenapall2504 3 года назад

    according to algorith ans to 1 5 5 is 4 but the true ans is 3

    • @nikoo28
      @nikoo28  3 года назад

      Can you describe the 3 steps to make the distribution equal?

    • @uttamkumarreddygaggenapall2504
      @uttamkumarreddygaggenapall2504 3 года назад

      Adding 5
      6 10 5
      Adding 5
      11 10 10
      Adding 1
      11 11 11

    • @aakrandan
      @aakrandan 3 года назад +1

      @@nikoo28 take 1 from first ==> 1 operation
      take 5 from second ==> 2 operation
      take 5 from third ==> 3operation
      Not sure if 0,0,0 can be the answer or not.

    • @nikoo28
      @nikoo28  3 года назад +2

      ​@@aakrandan 3 is the correct answer. If you try to run the code I have provided, it will give you the answer 3.
      I think from my explanation you missed the part to check for a range of "min" to "min - 4"

    • @yashgupta6797
      @yashgupta6797 2 года назад

      consider min from [min,min-4]

  • @vikasgowdalv770
    @vikasgowdalv770 3 года назад +1

    Worst voice ever heard :)

    • @nikoo28
      @nikoo28  3 года назад

      Thanks for your feedback, in an effort to constantly improve please let me know what kind of issues did you face.
      I will try to improve it in my next video.

    • @sheikhyawar2628
      @sheikhyawar2628 3 года назад +8

      You have nothing to do with his voice, he is doing a great job let him continue you just focus on your voice.we don't come here to judge his voice but to understand his problem solving technique.

    • @vikasgowdalv770
      @vikasgowdalv770 3 года назад

      @@sheikhyawar2628 BTW brother, I never commented on his problem solving skills ik he's a good problem solver
      And moreover I'll comment what I feel
      @Study Algorithms pleas do use autotuned voice it's really difficult to listen
      Hope you understand:)