
        while x != 0:
            if x > 0:
                remainder = x % 10
                x = x // 10

                if new_x > max_int // 10:
                    return 0
                elif new_x == max_int // 10 and remainder > 7:
                    return 0

            else:
                remainder = 10 - x % 10
                # Eg. -10