6 kyu
N smallest elements in original order (performance edition)
170 of 277FArekkusu
Description:
This challenge is based on a kata by GiacomoSorbi. Before doing this one it is advisable to complete the non-performance version first.
Task
You will be given an array of integers in a [1; 50]
range, and a number n
. You have to extract n
smallest elements out of the array preserving their original order.
Notes
- There will be duplicates in the array, and they have to be returned in the order of their each separate appearence.
- This kata is an example of the "know your data" principle. Remember this while searching for the correct approach.
Examples
numbers = [1, 2, 3, 4, 5]
n = 3
result = [1, 2, 3]
numbers = [5, 4, 3, 2, 1]
n = 3
result = [3, 2, 1]
numbers = [1, 2, 4, 1, 2]
n = 3
result = [1, 2, 1]
Algorithms
Arrays
Performance
Similar Kata:
Stats:
Created | May 6, 2018 |
Published | May 6, 2018 |
Warriors Trained | 1455 |
Total Skips | 27 |
Total Code Submissions | 4503 |
Total Times Completed | 277 |
Python Completions | 170 |
JavaScript Completions | 94 |
Rust Completions | 35 |
Total Stars | 37 |
% of votes with a positive feedback rating | 81% of 93 |
Total "Very Satisfied" Votes | 69 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 12 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 6 kyu |