6 kyu
Sort the number sequence
358 of 930myjinxin2015
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description
You are given a number sequence (an array) that contains some positive integer and zero.
[3,2,1,0,5,6,4,0,1,5,3,0,4,2,8,0]
It can be split to some zero-terminated sub sequence, such as [3,2,1,0], [5,6,4,0] ..
Your task is: First, sort each sub sequence according to the ascending order (don't sort the zero, it always at the end); Second, sort all sub sequence according to their sum value (ascending order too).
Arguments:
sequence
: The number sequence.
Results & Note:
- The result is the sorted number sequence.
- If some sub sequences have the same sum value, sort them according to their original order.
Some Examples
sortSequence([3,2,1,0,5,6,4,0,1,5,3,0,4,2,8,0]) should return
[1,2,3,0,1,3,5,0,2,4,8,0,4,5,6,0]
sortSequence([3,2,1,0,5,6,4,0,1,5,3,0,2,2,2,0]) should return
[1,2,3,0,2,2,2,0,1,3,5,0,4,5,6,0]
sortSequence([2,2,2,0,5,6,4,0,1,5,3,0,3,2,1,0]) should return
[2,2,2,0,1,2,3,0,1,3,5,0,4,5,6,0]
Puzzles
Sorting
Algorithms
Similar Kata:
Stats:
Created | Oct 31, 2016 |
Published | Oct 31, 2016 |
Warriors Trained | 2799 |
Total Skips | 60 |
Total Code Submissions | 8961 |
Total Times Completed | 930 |
JavaScript Completions | 358 |
Haskell Completions | 54 |
Python Completions | 539 |
λ Calculus Completions | 3 |
Total Stars | 77 |
% of votes with a positive feedback rating | 93% of 194 |
Total "Very Satisfied" Votes | 172 |
Total "Somewhat Satisfied" Votes | 15 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |