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.
publicstaticintchocolateFeast(intn,intc,intm){// Write your code here//n is the number of money Bobby has, he uses once//Bobby takes full advantage of promotion, hence, wrappers are used many times//Steps:/* 1. Calculate intial bars, also intial wrappers. 2. Create a loop, until Bobby cant trade, that updates bars and new wrappers (remain ones + traded ones) 3. Return result */intbars=n/c;//Initial barsintremainWrapper=bars;//Inital wrappers while(remainWrapper>=m){//While he can tradeinttrade=remainWrapper/m;remainWrapper=remainWrapper-trade*m+trade;//remainWrapper = remainWrapper % m + trade;bars+=trade;}returnbars;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Chocolate Feast
You are viewing a single comment's thread. Return to all comments →
My solution in Java 8: