> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/weekly-contest/weekly-contest-276/2139.-minimum-moves-to-reach-target-score.md).

# 2139. Minimum Moves to Reach Target Score

### greedy

T : O(n), n is maxDoubles

S: O(1)

```java
class Solution {
    public int minMoves(int target, int maxDoubles) {
        if (target == 1) {
            return 0;
        }
        int count = 0;
        for (int i = 0; i < maxDoubles; i++) {
            int remain = target%2;
            if (remain != 0) {
                count++;
            }
            target /= 2;
            count++;
            if (target == 1) {
                break;
            }
        }
        count += target - 1;
        return count;
    }
}

/*
Given the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.

10/2 = 5
            5/2 =2
            
            d
            d
            1
            d
            
19/2 = 9, reamin 1
9/2 = 4, reamin 1  max use out
4-1 = 3

*/
```
