You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.

In one move, you can either:


	Increment the current integer by one (i.e., x = x + 1).
	Double the current integer (i.e., x = 2 * x).


You can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.

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

&nbsp;
Example 1:

Input: target = 5, maxDoubles = 0
Output: 4
Explanation: Keep incrementing by 1 until you reach target.


Example 2:

Input: target = 19, maxDoubles = 2
Output: 7
Explanation: Initially, x = 1
Increment 3 times so x = 4
Double once so x = 8
Increment once so x = 9
Double again so x = 18
Increment once so x = 19


Example 3:

Input: target = 10, maxDoubles = 4
Output: 4
Explanation: Initially, x = 1
Increment once so x = 2
Double once so x = 4
Increment once so x = 5
Double again so x = 10


&nbsp;
Constraints:


	1 &lt;= target &lt;= 109
	0 &lt;= maxDoubles &lt;= 100


class Solution:
    def minMoves(self, target: int, maxDoubles: int) -> int:
        c=0
        while(maxDoubles>0 and target>1):
            c += target%2
            target //= 2
            c += 1
            maxDoubles -=1
        return c + target-1
class Solution {
    public int minMoves(int target, int maxDoubles) {
        int ans = 0;
        for(int i=0;i<maxDoubles;i++){
            if(target==1)break;
            
            if(target%2==0){
                ans+=1;
                target=(target)/2;
            }else{
                 ans+=2;
                target=(target-1)/2;
            }
        }
        return ans+target-1;
    }
}
class Solution {
public:
    int minMoves(int target, int maxDoubles) {
        int cnt = 0;
        while(target>1 && maxDoubles>0){
            if(target%2==0){
                cnt++;
                maxDoubles--;
                target = target/2;
            }
            else{
                cnt++;
                target--;
            }
        }
        return cnt + (target-1);
    }
};
var minMoves = function(target, maxDoubles) {
    if (maxDoubles === 0) return target - 1;
    let count = 0;

    while (target > 1) {
        if (target % 2 === 0 && maxDoubles > 0) {
            target /= 2;
            maxDoubles--;
        } else {
            target--;
        }

        count++;
    }

    return count;
};
Minimum Moves to Reach Target Score