6 kyu
Simple Fun #336: Lonely Frog
101 of 178myjinxin2015
Description:
Task
You are a lonely frog.
You live on a coordinate axis.
The meaning of your life is to jump and jump ..
The only rule is that each jump is 1 units more than the last time.
Now, here comes your new task. Your starting point is 0, the target point is n
.
Your first jump distance is 1, and the second step is 2, and so on ..
Of course, you can choose to jump forward or jump backward.
You need to jump to the target point with minimal steps
. Please tell me, what's the minimal steps
?
-10^7 <= n <= 10^7
Example
For n = 2
, the output should be 3
.
step 1: 0 -> 1 (Jump forward, distance 1)
step 2: 1 -> -1 (Jump backward, distance 2)
step 3: -1 -> 2 (Jump forward, distance 3)
For n = 6
, the output should be 3
.
step 1: 0 -> 1 (Jump forward, distance 1)
step 2: 1 -> 3 (Jump forward, distance 2)
step 3: 3 -> 6 (Jump forward, distance 3)
For n = 7
, the output should be 5
.
step 1: 0 -> 1 (Jump forward, distance 1)
step 2: 1 -> 3 (Jump forward, distance 2)
step 3: 3 -> 6 (Jump forward, distance 3)
step 4: 6 -> 2 (Jump backward, distance 4)
step 5: 2 -> 7 (Jump forward, distance 5)
Algorithms
Similar Kata:
Stats:
Created | Jun 29, 2017 |
Published | Jun 29, 2017 |
Warriors Trained | 812 |
Total Skips | 10 |
Total Code Submissions | 1184 |
Total Times Completed | 178 |
JavaScript Completions | 101 |
Haskell Completions | 12 |
COBOL Completions | 4 |
Python Completions | 72 |
Total Stars | 28 |
% of votes with a positive feedback rating | 95% of 46 |
Total "Very Satisfied" Votes | 42 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |