Minimum number of steps to reach a given number.
Submissions: 4840   Accuracy:

19.16%

  Difficulty: Medium   Marks: 4

Given a number line from -infinity to +infinity. You start at 0 and can go either to the left or to the right. The condition is that in i’th move, you take i steps. You are given a Destination , you have to print the minimum number of steps required to reach that destination.

Input:
The first line of the input contains the number of test cases T, then T lines follow and each lines contains an integer D specifying the destination.


Output:
Corresponding to each test case print in a new line the minimum number of steps required to reach that destination.

Constraints:
1<=T<=100
0<=D<=1000

Example:
Input:

2
2
10

Output:
3
4

Explanation:

In the first test case we can go from 0 to 1 (1 step) and then from 1 to -1 (2 steps) and then from -1 to 2 (3 steps). So in 3 steps we have reached our destination by taking i steps in ith turn.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Yash Kodesia
Author: Yash Kodesia 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.