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.
public static int howManyGames(int p, int d, int m, int s)
{
// Return the number of games you can buy
int games = 0;
for(int spent = p; spent <= s; spent += GetSpent(games, p, d, m, spent))
games++;
return games;
}
public static int GetSpent(int games, int p, int d, int m, int spent)
{
if(p - d*games < m)
return m;
else
return p - d*games;
}
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 →
C# Solution