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.
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.
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.
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
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.
@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
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.
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.
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?
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.
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 😅😅
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.
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)
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.
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.
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.
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.
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.
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.
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.
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?!
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
That was a very good explanation Sir!
You have kept the logic in simple and short way.
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.
so what should someone who is preparing for interviews do? just cram em?
This question is so poorly explained on hackerrank.
exactly
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.
This felt infinitely more complicated on Hackerrank. Thank you for explaining how simple the solution truly is!
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.
C'était une très bonne explication, monsieur ! Je vous remercie de votre attention.
you are a gifted teacher sir. Thank you for putting in the time to break this down
Thank you for the crystal clear explanation!
Excellent video mr Praveen.Thank you
Excellent Mr.Praveen, keeping making more and more videos
Great explanation, thank you.
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
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.
@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
Amazing explanation, thank you!
Good explanation...❤❤
Hi Praveen Thank you for the explanation. You made it very easy to understand!
Glad it was helpful!
Well explained.👏
Glad you liked it
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.
Hmmmm
And why it should solve it mathematically?
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.
Thank you so much for such great explanation!
thank u sir for the explanation
Very nice solution. :)
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?
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.
Woow .. what an observation
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 😅😅
awsome xplanation,
saves my times
Que viva la India🤩
Wow, nice, thank you
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.
They are both 3 units tall, then they are 2 and 1, after one player moves, that makes no sense
Isn't 2 also a valid move in the first exercise example, since 2 divides 6 evenly?
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)
@@renatobrant7719Thanks for clarifying. I came to the same conclusion the other day.
Thanks!
thanks alot, you made it very easy to understand.
Glad to hear that!
just a simple issue and I magnify it to the one I cant image what is this thing :))))
Thank you
Thanks sir
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.
It is written in the problem that the towers have the same height.
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.
I think step 2 wouldn’t be like you said because that move affects player 2. He should know it.
i think when let say m = 4 , n = 3 i.e odd , there are cases when player 1 or two both could lose.
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.
நன்றிகள்
நான் ஜப்பானிய மொழியில் நன்றிக் கருத்தைப் பெற்றிருந்தேன். என் தாய்மொழியான தமிழில் கிடைத்ததில் மிகவும் மகிழ்ச்சி
@@shabrishpraveen1 உங்களைப் போன்ற தமிழர்கள் தாய் மொழியை நேசிப்பது மிகவும் மகிழ்ச்சி.
thank you man!
Happy to help!
Is there a more air-tight explanation for why it works that way? Like not through examples but throgh sth like mathematical induction
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.
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.
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.
How can new height Y be divisible by old height X if Y < X ? How's that possible?
sir please add full video of 1 week interview prepartion in hackerrank
Noted. I am super occupied next couple of weeks. I have added this to my todo list :)
@@shabrishpraveen1 thank you sir
ありがとう
Is it an exception when n=1, m=5? (Player 2 can win this game)
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.
But all test casess are not passed????
Yes Leela, all test cases got passed 👍
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?!
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
sewwy
No le entiendo nada a los indios cuando hablan ingles 😂, indians need to pronounce better
Who told you he was an Indian ?
Thank you
You're welcome!