6 kyu
Fastest Code : Excel Puzzle #2
Description:
This is the Performance version of coding 3min series. If your code got timeout, please optimize your code or try the simple version
Task:
You are given two arguments: excel
(number array), like this:[1 ,2 ,3 ,4 ,5 ,6]
, and n
(an index of target number)
Return the rank of excel[n].
The rank means, when excel
in ascending order, what is its position.
In this performance version, excel length : small data 5...99, big data:400000, elements of excel value range: 0...99
Some example to help you understand the rules:
solveIt([1,2,3,4,5],0)=1
rank: 1 2 3 4 5
excel[0]=1, rank of number 1 is 1
solveIt([1,2,3,4,5],1)=2
rank: 1 2 3 4 5
excel[1]=2, rank of number 2 is 2
solveIt([5,4,3,2,1],0)=5
rank: 5 4 3 2 1
excel[0]=5, rank of number 5 is 5
solveIt([5,4,3,2,1],1)=4
rank: 5 4 3 2 1
excel[1]=4, rank of number 4 is 4
so easy? see other examples:
solveIt([1,2,2,2,3],1)=2
rank: 1 2 3 4 5
the same number have diffrent ranks,
the number of smaller indexes is in front of others.
excel[1]=2, rank of first number 2 is 2
solveIt([1,2,2,2,3],2)=3
rank: 1 2 3 4 5
excel[2]=2, rank of second number 2 is 3
solveIt([2,2,2,2,2],2)=3
rank: 1 2 3 4 5
excel[2]=2, rank of 3rd number 2 is 3
Please use the sort function carefully, because the original array should not be changed.
Series:
Puzzles
Games
Algorithms
Similar Kata:
Stats:
Created | Apr 25, 2016 |
Published | Apr 25, 2016 |
Warriors Trained | 164 |
Total Skips | 14 |
Total Code Submissions | 159 |
Total Times Completed | 57 |
JavaScript Completions | 57 |
Total Stars | 2 |
% of votes with a positive feedback rating | 88% of 30 |
Total "Very Satisfied" Votes | 25 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |