Sort by

recency

|

1263 Discussions

|

  • + 0 comments

    This problem is a geometric series so can be solved with maths.

    int chocolateFeast(int n, int c, int m) {
        return ((long)(n/c)*m-1)/(m-1);
    }
    
  • + 0 comments

    Here is my easy c++ solution , you can watch the explanation here : https://youtu.be/RZti_qPbiAA

    int chocolateFeast(int n, int c, int m) {
        int result = 0, wrappers = 0;
        while( n >= c){
            result ++;
            wrappers ++;
            n -= c;
            if(wrappers == m){
                result ++;
                wrappers = 1;
            }
        }
        return result;
    }
    
  • + 0 comments
    def chocolateFeast(n, c, m):
        a=o=n//c
        for _ in range(5):
          if a<m:
            break
          o+=(a//m)
          a=(a//m)+(a%m)
        return o
    
  • + 0 comments

    def chocolateFeast(n, c, m): bars = n//c wrap = bars while w:=wrap//m: bars += w wrap = w + wrap% m return bars

  • + 0 comments

    int chocolates = n / c; int exchange_wrappers = chocolates;

        do{
            int rem = exchange_wrappers % m;
            exchange_wrappers = exchange_wrappers / m;
            chocolates += exchange_wrappers;
            exchange_wrappers = exchange_wrappers + rem;
    
        }while(exchange_wrappers >= m);
    
        return chocolates;