Broken Calculator

Problem Id: 991 Difficulty: Medium


Intuition

Solution


class Solution:
    def brokenCalc(self, X: int, Y: int) -> int:
        steps = 0
        while Y > X:
            if Y % 2 == 1:
                Y += 1
                steps += 1
            else:
                Y //= 2
                steps += 1
        return steps + X - Y