Find a number in minimum steps - GeeksforGeeks
Given an infinite number line from -INFINITY to +INFINITY and we are on zero. We can move n steps either side at each n'th time.
1st time; we can move only 1 step to both ways, means -1 1; 2nd time we can move 2 steps from -1 and 1; -1 : -3 (-1-2) 1(-1+2) 1 : -1 ( 1-2) 3(1+2) 3rd time we can move 3 steps either way from -3, 1, -1, 3 -3: -6(-3-3) 0(-3+3) 1: -2(1-3) 4(1+3) -1: -4(-1-3) 2(-1+3) 3: 0(0-3) 6(3+3) Find the minimum number of steps to reach a given number n.
Read full article from Find a number in minimum steps - GeeksforGeeks
No comments:
Post a Comment