Sort by

recency

|

675 Discussions

|

  • + 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;
    
  • + 0 comments

    public static int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy

        int n=0;        
    
        while(s-p>=0)
        {            
            n++;
            s-=p;            
            p-=d;
    
            if(p<=m)
            {
                p=m;
            }      
        }
    
        return n;
    }
    
  • + 0 comments
    def how_many_games(p, d, m, s):
        if s < p:
            return 0
        c = 0
        while s >= m:
            s -= (p - c*d) if ((p - c*d) >= m) else m
            c += 1 if s >= 0 else 0
        return c
    
  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-halloween-sale-problem-solution.html

  • + 0 comments

    PYTHON If in dought pls ask

    def howManyGames(p, d, m, s):
        # Return the number of games you can buy
        games=0
        i=0
        while s>=0:
            cost=p-d*i
            if cost>m:
                s-=cost
            else:
                s-=m
            games+=1
            i+=1
        return games-1