Hurdle Game
Once Kevin is playing a hurdle game in which he has to jump some hurdles to clear a particular level. Each level ‘i’ has ‘i’ hurdles (for example, level 6 has 6 hurdles).
You are provided with the total number of hurdles that Kevin has jumped, you have to tell how many levels he has cleared.
Note :
Kevin has played this game once. He can only reach the level ‘i’ if and only if he has already cleared the level (‘i’ - 1).
Input Format :
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a single integer ‘N’ which represents the total number of hurdles that Kevin has jumped.
Output Format :
For each test case, print an integer denoting the number of levels that Kevin has cleared.
Output for every test case will be printed in a separate line.
Note :
You don’t need to print anything; It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 50
0 <= N <= 10 ^ 8
Time limit: 1 sec
AnswerBot
1y
The task is to determine the number of levels cleared by Kevin based on the total number of hurdles he has jumped.
Each level 'i' has 'i' hurdles, so Kevin can only reach level 'i' if he has cleared le...read more
CodingNinjas
author
2y
Brute Force
The basic idea is to iterate through all the levels and keep subtracting the hurdles that Kevin has jumped. The steps are as follows:
- Create two variables “hurdle” and “level” to count the ...read more
CodingNinjas
author
2y
Mathematics
The basic idea of this approach is to generate a mathematical equation to solve this problem. Hurdles at a particular level are increased by 1 as compared to their previous level and so,
w...read more
Add answer anonymously...
Top Rupeek Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Rupeek Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app