Given start value and target , you can double or subtract . Find minimum operations to reach . For , : double to , subtract to . Answer is . Going forward is hard because doubling can overshoot.
Think about working backwards from to . Tricky: working forward with doubling can overshoot , making it hard to determine the optimal path. Working backward with halving and adding is deterministic: if is even, halving is always better than adding (halving reduces by half, adding by ).
This guides the greedy choice.