Code A Primitive Calculator ( x3,x2,+1) Using Dynamic programming
Edit
I realized that my distinction between bottom-top and top-bottom might have caused some confusion. Going top to bottom and bottom to top is the exact same thing, just switched the starting and end points. I just made a habit of thinking about it differently. It's an unnecessary distinction (sorry for any confusion). But the general algorithm is the same.
More detailed explanation:
Just as explained below, you can start at 96234. You check the ways to get to 96233. There is only one way (subtract 1) so it is automatically the least moves. The numbers of moves it takes is 1 + number of moves takes to get to 96234, which is 0. So you store 1 into 96233. You do the same thing for 96232, 96231...
...You get to 32078, you check the paths to get there, /3 from 96234, /2 from 64156, -1 from 32079. The paths each have moves 1, 32079, and 64156 respectively. You store the smallest into the current slot.
Eventually, you get to 1, and you compare the values stored at slots 2,2,and 3. You return the lowest one + 1.
Previous Answer
Shouldn't you be going from bottom to top? Your code is doing exactly what you're telling it to do. You check if n%2==0 first, before you ever do n=n-1. That works most of the time, but as you can see, sometimes n-1 is less moves.
You won't be able to know which is the best operation if you go from top to bottom.
Instead, you should start at 1, and calculate the least amount moves it takes to get to 2,3,4... all the way to 96234. This is still of O(n), and memory wise, it is O(n) although I think you can get it down with a trick (not sure).