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.
staticinthowManyGames(intp,intd,intm,ints){// Return the number of games you can buyintcount=0;//an int variable for counting the no of games that i can buyif(s<p){//checking if my amount of money is less than of first time price of the game or notreturncount;//if my money is less then i can't buy any game so i returning 0}// if i have sufficient money to buy atleast one game then execute the below codewhile(s>=p){//a loop that checking until and unless i have money to buy gamescount++;//by every condition satisfaction no of bought game is increasing s=s-p;//deducting my amount of money for every game purchaseif(p>m){//checking the lowest limit of selling price of the game can be deducted by d for every purchasingp=p-d;//changing the selling price after every deduction}if(p<m){//check if the selling should not be less than mp=m;}}returncount;//returning the no of games i had bought}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Halloween Sale
You are viewing a single comment's thread. Return to all comments →
simpliest solution for any language