Tower breakers. Simple solution with explanation for HackerRank challenge

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024
  • Tower Breakers HackerRank challenge. Simple solution with clear explanation.

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

  • @jasondsouza7302
    @jasondsouza7302 2 года назад +20

    That was a very good explanation Sir!
    You have kept the logic in simple and short way.

  • @ricardomiranda7737
    @ricardomiranda7737 2 года назад +35

    Great explanation, thank you. What is aggravating is that a lot of these challenges don't really test your ability to code. Many of these focus more on pattern recognition and developing algorithms based on those recognized patterns. Some of these problems are ill conceived.

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

      so what should someone who is preparing for interviews do? just cram em?

  • @MrRANDUM145
    @MrRANDUM145 2 года назад +42

    This question is so poorly explained on hackerrank.

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

      exactly

    • @laurengraham9325
      @laurengraham9325 5 месяцев назад +2

      Nice to know I'm not the only one. I got a max score in reading on the ACT but when I read hackerrank questions it's like my reading comprehension is low. I am too literal for the way they are worded.

  • @jackelinelopez1864
    @jackelinelopez1864 Месяц назад +1

    This felt infinitely more complicated on Hackerrank. Thank you for explaining how simple the solution truly is!

  • @stanislavmozolevskiy8346
    @stanislavmozolevskiy8346 2 года назад +20

    Thank you for the quick and easy to understand explanation for this dumb challenge that should not be a coding challenge but more like a math or logic related.

  • @renanrosa5527
    @renanrosa5527 7 дней назад +1

    C'était une très bonne explication, monsieur ! Je vous remercie de votre attention.

  • @mevanscodes
    @mevanscodes 2 года назад +8

    you are a gifted teacher sir. Thank you for putting in the time to break this down

  • @HariPrasad-ox5ri
    @HariPrasad-ox5ri 6 месяцев назад +1

    Thank you for the crystal clear explanation!

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

    Excellent video mr Praveen.Thank you

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

    Excellent Mr.Praveen, keeping making more and more videos

  • @brscn2
    @brscn2 10 месяцев назад +1

    Great explanation, thank you.

  • @rocioarteaga7606
    @rocioarteaga7606 2 года назад +9

    I dont understand how when you have 3 towers of m=3 player 2 can reduce the tower from 3 to 2. Since y has to be divisible by x but 2 isnt divisible by 3 or am i misunderstanding

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

      I think that this was by mistake and what author meant in this case was 3 towers of even height, for example 4. Otherwise the solution would lack this case of odd number of towers of even height.

    • @sushmasenthilsenthilkumar6993
      @sushmasenthilsenthilkumar6993 Год назад +3

      @Rocio The thing is that the new height(y) has to be the divisible of current height(x) . For example 3 is reduced to 1 here 1(y->new height) is the divisible factor of 3(x-> current height).Don't consider the reduced height 2

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

    Amazing explanation, thank you!

  • @vishnoo_prasad_m
    @vishnoo_prasad_m 10 месяцев назад +1

    Good explanation...❤❤

  • @CarlFike
    @CarlFike 5 месяцев назад +1

    Hi Praveen Thank you for the explanation. You made it very easy to understand!

  • @arunreddy4459
    @arunreddy4459 3 месяца назад +1

    Well explained.👏

  • @JillShermanful
    @JillShermanful 2 года назад +5

    This solution doesn't explain how to solve the problem mathematically using the function. Just shows through examples the conditions in which player 1 would win vs when player 2 would win, and solves the problem with an if/else.

  • @oswaldorodriguez1453
    @oswaldorodriguez1453 Год назад +8

    I saw this exercise in hackerrank. and I could not even understand the requirements. Very confusing in my opinion which it was suposed to evaluate algotithms rather than tricky questions.

  • @roshaninavdiya9173
    @roshaninavdiya9173 11 месяцев назад +1

    Thank you so much for such great explanation!

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

    thank u sir for the explanation

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

    Very nice solution. :)

  • @mohammadyahya78
    @mohammadyahya78 Год назад +4

    Thank you. But the problem says that you choose a tower of height x and reduce its height to y, where y evenly divides x. In 4:00, you took 3 from tower of height 4, where 3 does not evenly divides 4, please correct me if I am wrong?

    • @calvimor_
      @calvimor_ Год назад +3

      Following the example you say, if you took 3 of tower height 4, the new height will be 1, this is the value of y, and should be divisor of 4. It does not mean that the value you take to reduce (3) is y.

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

    Woow .. what an observation

  • @XDoggoX
    @XDoggoX Год назад +3

    Is there a mathematical explanation? To be honest, I have no taste of why the problem behaves that way.
    Anyways, thanks for the explanation. It's tricky to understand the problem statement 😅😅

  • @aasimahsan6167
    @aasimahsan6167 9 месяцев назад

    awsome xplanation,
    saves my times

  • @yamirc735
    @yamirc735 Месяц назад +1

    Que viva la India🤩

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

    Wow, nice, thank you

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

    The exmple they gave confused me Player matches the move. Now the towers are both 3 units tall.
    Now Player has only one move.
    Player removes pieces leaving . Towers are 1 and 2 units tall.
    Player matches again. Towers are both unit tall.

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

      They are both 3 units tall, then they are 2 and 1, after one player moves, that makes no sense

  • @ralphwbms
    @ralphwbms 2 года назад +5

    Isn't 2 also a valid move in the first exercise example, since 2 divides 6 evenly?

    • @renatobrant7719
      @renatobrant7719 2 года назад +9

      Yes, it is also a valid move.
      However, in terms of next moves avaiable, reducing the tower to 2 is equals to reducing it to 3, since both cases leave you with only one next possible move, which is reduce the tower to 1.
      So in practice reducing it to 3 or to 2 is the same, that's why it only shows one of the options.
      (I also had the same question when solving the problem)

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

      @@renatobrant7719Thanks for clarifying. I came to the same conclusion the other day.

  • @mohammadreza.beygifard
    @mohammadreza.beygifard 6 месяцев назад +1

    Thanks!

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

    thanks alot, you made it very easy to understand.

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

    just a simple issue and I magnify it to the one I cant image what is this thing :))))

  • @jabahunter
    @jabahunter 11 месяцев назад

    Thank you

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

    Thanks sir

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

    If it number of towers is even, player 2 wins always.
    But I have a problem:
    Take two tower A and B.
    A has 4 and b has 2.
    Player 1 reduces A to 2.
    Now, in all the cases, player 1 wins!! Which contradicts the above statement.

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

      It is written in the problem that the towers have the same height.

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

    I need help undersanding this scenario. There are 2 towers with height of 6 each (n=2, m=6).
    step 1) Player 1 reduces the height of tower 1 to 3. new_height = 3 which is evenly divisible by 6.
    step 2) Player 2 reduces the height of tower 1 to 1. new-height of tower 1 is now 1.
    step 3) Player 1 reduces the height of tower 2 to 1. new-height of tower 2 is not 1. And, player 2 has no possible move. So player 1 wins.

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

      I think step 2 wouldn’t be like you said because that move affects player 2. He should know it.

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

    i think when let say m = 4 , n = 3 i.e odd , there are cases when player 1 or two both could lose.

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

      There cannot be a case when both players could lose because it would mean that one of the players made a mistake. There is no random in this game and it is given that both players play optimally.

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

    நன்றிகள்

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

      நான் ஜப்பானிய மொழியில் நன்றிக் கருத்தைப் பெற்றிருந்தேன். என் தாய்மொழியான தமிழில் கிடைத்ததில் மிகவும் மகிழ்ச்சி

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

      @@shabrishpraveen1 உங்களைப் போன்ற தமிழர்கள் தாய் மொழியை நேசிப்பது மிகவும் மகிழ்ச்சி.

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

    thank you man!

  • @anniedong8751
    @anniedong8751 9 месяцев назад

    Is there a more air-tight explanation for why it works that way? Like not through examples but throgh sth like mathematical induction

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

    I don't understand bottom example at "Game ON Even Towers". Player1 could win if:
    Move #1: P1 reduces tower1 to height 1
    Move #2: P2 reduces tower2 to height 2
    Move #3: P1 reduces tower2 to height 1
    P2 can not move, so they lose.

  • @user-wq7hh1tx3q
    @user-wq7hh1tx3q Год назад

    This does not meet this requirement:
    In each turn, a player can choose a tower of height and reduce its height to , where and evenly divides .
    i.e. if a tower's height is 4, then it can only be reduced by 2 or 1, not by 3.

    • @naveenaas1009
      @naveenaas1009 Год назад +3

      The problem requires the resulting height of tower to evenly divide the initial height. Say m is the initial height and it was reduced by i, then (m-i) should be divisible by m. In your example, 4 can be reduced TO (and not BY) 2 or 1, since both 2 and 1 divides 4. The value 3 doesn't have much of a role in the rules.

  • @olexandrberdnikov9149
    @olexandrberdnikov9149 3 дня назад

    How can new height Y be divisible by old height X if Y < X ? How's that possible?

  • @sankaranarayanankm7049
    @sankaranarayanankm7049 5 месяцев назад

    sir please add full video of 1 week interview prepartion in hackerrank

    • @shabrishpraveen1
      @shabrishpraveen1  5 месяцев назад

      Noted. I am super occupied next couple of weeks. I have added this to my todo list :)

    • @sankaranarayanankm7049
      @sankaranarayanankm7049 5 месяцев назад

      @@shabrishpraveen1 thank you sir

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

    ありがとう

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

    Is it an exception when n=1, m=5? (Player 2 can win this game)

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

      I guess the statement "both players always play optimally" takes care of that. Player 1 will not leave behind anything more than 1, since it will be trivial for Player 2 to win in that case.

  • @leela7002
    @leela7002 11 месяцев назад

    But all test casess are not passed????

  • @MrEniyavan
    @MrEniyavan 3 месяца назад

    Very poorly Written in Hackerrank. After seeing this explanation we were able to arrive a solution. Is this some strategy tried by hackerrank to confuse candidates?!

    • @shabrishpraveen1
      @shabrishpraveen1  10 дней назад

      Actually these questions or similar ones are asked during Amazon interviews. They expect people to understand such complex problems. Once we started understanding and solving a few then our brain 🧠 gets trained and we start easily solving them sir

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

    sewwy

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

    No le entiendo nada a los indios cuando hablan ingles 😂, indians need to pronounce better

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

      Who told you he was an Indian ?

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

    Thank you