Search
⌘K

Leetcode 397. Integer Replacement

Given a positive integer n, repeatedly apply n/2 if n is even or either n+1 or n−1 if n is odd and return the minimum number of moves to reach 1. The core challenge is choosing the optimal increment vs decrement for odd n (often solved with bit-manipulation/greedy or BFS/DP), with inputs up to 2^31−1.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.