7 kyu
Broken sequence
986 of 4,393suuuzi
Description:
You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4).
Return:
0
if the elements can form such a sequence, and no number is missing ("not broken", e.g."1 2 4 3"
)1
if there are any non-numeric elements in the input ("invalid", e.g."1 2 a"
)n
if the elements are part of such a sequence, but some numbers are missing, andn
is the lowest of them ("broken", e.g."1 2 4"
or"1 5"
)
Examples
"1 2 3 4" ==> return 0, because the sequence is complete
"1 2 4 3" ==> return 0, because the sequence is complete (order doesn't matter)
"2 1 3 a" ==> return 1, because it contains a non numerical character
"1 3 2 5" ==> return 4, because 4 is missing from the sequence
"1 5" ==> return 2, because the sequence is missing 2, 3, 4 and 2 is the lowest
Strings
Fundamentals
Similar Kata:
Stats:
Created | Mar 25, 2015 |
Published | Mar 25, 2015 |
Warriors Trained | 15351 |
Total Skips | 3137 |
Total Code Submissions | 50183 |
Total Times Completed | 4393 |
Java Completions | 986 |
Python Completions | 1354 |
JavaScript Completions | 1523 |
Ruby Completions | 607 |
Total Stars | 250 |
% of votes with a positive feedback rating | 87% of 892 |
Total "Very Satisfied" Votes | 697 |
Total "Somewhat Satisfied" Votes | 151 |
Total "Not Satisfied" Votes | 44 |
Total Rank Assessments | 230 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 2 kyu |
Lowest Assessed Rank | 8 kyu |