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

Stats:

CreatedApr 25, 2016
PublishedApr 25, 2016
Warriors Trained164
Total Skips14
Total Code Submissions159
Total Times Completed57
JavaScript Completions57
Total Stars2
% of votes with a positive feedback rating88% of 30
Total "Very Satisfied" Votes25
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes2
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • ZED.CWT Avatar
  • user9644768 Avatar
Ad