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.
// Creating a memoization cache for the nmax functionconstcache=newMap();// Defining the nmax function to calculate the maximum number of pilesfunctionnmax(cost){if(cost<4)return1;if(cache.has(cost))returncache.get(cost);letsum=0;for(letpile=1;pile<=Math.floor(Math.sqrt(cost));pile++){sum+=nmax(cost-Math.pow(pile,2));}cache.set(cost,sum);returnsum;}// Defining the towerBreakers function to find the minimum costfunctiontowerBreakers(n){for(letcost=0;;cost++){if(nmax(cost)>=n)returncost;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tower Breakers - The Final Battle
You are viewing a single comment's thread. Return to all comments →
Didn't see any solution in JS, so here you go.