• + 0 comments

    My solution in Python 3:

    def chocolateFeast(n, c, m):
        # Write your code here
        #n is the number of money Bobby has, he uses once
        #Bobby takes full advantage of promotion, hence, wrappers are used many times
            
        #Steps:
        '''
            1. Calculate intial bars, also intial wrappers.
            2. Create a loop, until Bobby cant trade, that updates bars and new wrappers (remain ones + traded ones)
            3. Return result
                
        '''
        
        bars: int = n / c 
        remain_wrappers: int = bars
        
        while remain_wrappers >= m:
            trade: int = remain_wrappers // m
            remain_wrappers = remain_wrappers % m + trade
            
            bars += trade
            
        return int(bars)