We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Whenever the height (m) is 1, Player 2 will win because Player 1 can't remove any pieces.
Similarly, when the number of towers (n) is even, Player 2 will win because he can remove as many pieces as Player 1. Consequently, Player 1 will be left with no choice in the end.
So,code in JavaScript will be like :
function towerBreakers(n, m) {
return m===1 || n%2 === 0 ? 2 : 1;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tower Breakers
You are viewing a single comment's thread. Return to all comments →
function towerBreakers(n, m) { return m===1 || n%2 === 0 ? 2 : 1; }