Interesting Device
Bob discovered a peculiar device with a green button, a purple button, and a display showing a positive integer. Pressing the green button doubles the number on the display, while pressing the purple button subtracts one from it. If the number becomes non-positive at any point, the device will break. The display is capable of showing very large numbers. Initially, the display shows the number n. Bill wants to transform the number on the display to m.
Given integers n and m, return a minimum number of button presses required to transform number n to m.
Example 1
Input:
n = 4; m = 6
Output:
2
main.cpp
C++
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat