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.
functionstoneDivision(n:number,s:number[]):number{/** * Build a recursion function that have * * + number [n] is size of a pile * + number [s] is set of divider * -> return 0 if [n] can't be divided by any of [s] * * recursion mean this couple can't be go furthur * -> return 1 if [n] can divided * * number [d] is a number in [s] that fit conditions * * number [n] can be divided multiple times, so multiply by [n]/[d] * * recursion mean this couple is nice, plus */constmemo:{[key:string]:number}={}constrecurse=(n:number):number=>{if(ninmemo)returnmemo[n]letmax=0for(letdofs){if(d!=n&&n%d==0){max=Math.max(max,1+(n/d)*recurse(d))}}returnmemo[n]=max}returnrecurse(n)}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Stone Division, Revisited
You are viewing a single comment's thread. Return to all comments →
My answer in Typescript