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.
funcostWithOffset(offset:Int):Int{valmin=arr.min();valadjustedArray=arr.map{offset+it-min};// every operation essentially "removes" 1, 2, or 5 from a single person (in terms of balance)valnumStepsRequired=adjustedArray.map{original->valfivesCount=original/5;valremainder=original%5;// steps required to handle remainder can be calculated as such:valremainderSteps=(remainder+1)/2;fivesCount+remainderSteps;}returnnumStepsRequired.sum();}// Need to check multiple offsets in case changing the lowest values' offsets results in less steps for othersreturn(0..4).map{costWithOffset(it)}.min();}
Equal
You are viewing a single comment's thread. Return to all comments →
Definitely no DP required for this problem: