Recursive cpp solution with time limit


#1

int path(int A, int pos, int i){
if((pos-A)%2==0 && pos>=abs(A)){
return --i;
}else{
return path(A,pos+i,i+1);
}
}

int Solution::solve(int A) {
return path(A,0,1);
}