Chief Hopper Discussions | | HackerRank

Chief Hopper

  • + 0 comments
    def chiefHopper(arr:list)->int:
        """
        LOGIC:
        We iterate the array from the end.
        If we check the formula, we got
        
        if bot energy is less than height
        newEnergy = botEnergy - (height - botEnergy) 
        and
        newEnergy = botEnergy +(botEnergy-height) if not.
        
        This two operations, when reduced get:
        newEnergy = 2*botEnergy - height
        So this is the operation we will perform from the back,
        keeping track of the result of each one to be used again
        in the inmediate before index.
    		For the initial value, we need to remember that, at the end, energy needs to be more than zero.
    		
    		
        """
        
        minimum = 0
        for height in reversed(arr):
            minimum = ceil((height+minimum)/2)
        return minimum