Sort by

recency

|

679 Discussions

|

  • + 0 comments
    def howManyGames(p, d, m, s):
        # Return the number of games you can buy
        count=0
        spent=0
        price=p
        while spent+price<=s:
            spent+=price
            count+=1
            price=max(price-d,m)
        return count
    
  • + 0 comments

    C++

    int howManyGames(int p, int d, int m, int s) {
        int cnt = 0;
        while (s >= p) {
            s -= p;
            p = max(p - d, m);
            cnt++;
        }
    
        return cnt;
    }
    
  • + 0 comments

    Lock repair Doncaster services offer reliable, efficient solutions for all types of lock issues, much like a Halloween sale brings exciting deals and opportunities. Skilled technicians ensure locks are fixed promptly, restoring security and peace of mind for homes and businesses. Their expertise covers a wide range of lock types and mechanisms. Choosing professional lock repair in Doncaster guarantees dependable service, enhanced safety, and long-lasting protection, just as a well-timed sale delivers value and satisfaction.

  • + 0 comments

    Node.js solution:

    function howManyGames(p, d, m, s) { let gamesBought = 0; while(s >= p){ s -= p; p = Math.max(p - d, m); gamesBought++; } return gamesBought; }

  • + 0 comments

    Why so many test cases?

    int games = 0;
        
        while(p>m && s>0){
            
            s-=p;
            
            if(s>0){
                games++;
                p-=d;
            }
        }
        
        if((s-m)>=0){
            return games + (s/m);
        }
        
        return games;