You are standing at position 0 on an infinite number line. There is a destination at position target.

You can make some number of moves numMoves so that:


	On each move, you can either go left or right.
	During the ith move (starting from i == 1 to i == numMoves), you take i steps in the chosen direction.


Given the integer target, return the minimum number of moves required (i.e., the minimum numMoves) to reach the destination.

&nbsp;
Example 1:

Input: target = 2
Output: 3
Explanation:
On the 1st move, we step from 0 to 1 (1 step).
On the 2nd move, we step from 1 to -1 (2 steps).
On the 3rd move, we step from -1 to 2 (3 steps).


Example 2:

Input: target = 3
Output: 2
Explanation:
On the 1st move, we step from 0 to 1 (1 step).
On the 2nd move, we step from 1 to 3 (2 steps).


&nbsp;
Constraints:


	-109 &lt;= target &lt;= 109
	target != 0


class Solution: 
  def  reachNumber(self,target):
    jumpCount = 1 
    sum = 0 
    while sum<abs(target):
      sum+=jump 
      jumpCount+=1 
    
    if (sum-target)%2==0: return jumpCount-1 
    else:
      
      if ((sum+jumpCount)-target)%2==0: 
        return jumpCount
      else:
        return jumpCount+1 
class Solution {
    public int reachNumber(int target) {
        int sum =0 ,steps = 0;
        if(target ==0) return 0;
        target = Math.abs(target);
        while(sum< target){
            sum+=steps;
            steps++;
        }
        
        while(((sum-target)%2!=0)){
            sum+=steps;
            steps++;
        }
        return steps-1;

    }
}
long long fun(long long a){ //sum of all natural from 1 to a
    long long b=a*(a+1)/2;
    return b;
}

class Solution {
public:
    int reachNumber(int target) {

         long long i=1,j=pow(10,5),x=abs(target),ans=0; //for -ve or +ve positive of a number the minimum no. of steps from the origin will be same

    while(i<=j){ // binary search to search if x is continous sum of some natural number starting from 1
        long long m=(i+j)/2;

        if(fun(m)==x){
            ans=m;
        }
        if(x>fun(m)){
            i=m+1;
        }
        else{
            j=m-1;
        }

    }

    if(ans!=0){ // If we found our ans return it

        return ans;
    }
    else{
     //in this for loop i have set the limit too high it can be less then 10^6 as max value j can be is 44723, so loop will never run fully, whatever the value of j will be, loop will maximum run for 3-10 iterations
    for(int l=j+1;l<100000;l++){ // in the end of binary search we get the value of j(or high end) as the position of the number(in the sequence of continous sum of natural number from 1, i.e. 1, 3,6,10........) whose value is just less than x(searching element)

        if((fun(l)-x)%2 ==0){ // as the total step will be more than x if we go backward from zero, thing to note is that if we go -ve direction we also have to come back so we covering even distance
             ans=l;// when the first fun(l) - x is even that l is our minimum jump

            break; // no need to search further

    }
    }

    }

        return ans;
    }

};
/**
 * @param {number} target
 * @return {number}
 */
var reachNumber = function(target) {
    target = Math.abs(target);
    let steps = 0, sum = 0;
    while (sum < target) {
        steps++;
        sum += steps;
    }
    while ((sum - target) % 2 !== 0) {
        steps++;
        sum += steps;
    }
    return steps;
};
Reach a Number