Simple Fun #401: Who Will Get The Autographed Photo Of Mr. Mxyzinjin?
Description:
Story & Task
Mr. Mxyzinjin is the greatest kata author in the world. He has many fans around the world.
Today, he received letters from x
fans. Fans want to get his autographed photos. But, he has only n
photos.
He plans to select n people from these fans and send out his photos.
According to the order of the letters, he gave each fan a ID number(let's say, id1), from 1 to x, where x is the total number of fans.
According to his initial impression, he gave each fan an initial weight.
Reordering the fans according to the initial weights, from big to small. If two fans have the same initial weight, the fan who has smaller id1 value is in front.
According to the order of current sequence, he gave each fan a new ID number(let's say, id2), from 1 to x, where x is the total number of fans.
He divided the fans into 10 kinds, according to the value of id2 mod 10. For example, 1, 11 and 21 are the same kind, 2, 12,22 are the same kind, etc.
Each kind of fans will plus a special weight.
Reordering the fans according to the current weights, from big to small. If two fans have the same weight, the fan who has smaller id1 value is in front. (Note, id1, not id2)
Finally, pick
n
fans from big weight to small weight, and send out his photos.
You are given the initial weights
, special weight
, and n
. Your task is to sort the data and select n
fans, return their id (id1).
Input
initWeights
. An integer array. Each element is the initial weight of each fan, according to the order of the letters.3<= initWeights.length <= 10000
specWeights
. An integer array. It always contains 10 elements, and each element represents a special weight of a kind of fans. 1st element for kind 1, 2nd element for kind2, and so on..n
. A positive integer. The number of selected fans.1 <= n <= 200
andn <= initWeights.length
Output
An array of n
fans' ids(id1), according to the order of final result after sort operations.
Example
For initWeights = [1,2,3,4], specWeights = [1,1,1,100,0,0,0,0,0,0], and n = 3
,
The output should be [1,4,3]
id1: 1 2 3 4
initial weight: 1 2 3 4
sort by weight:
id1: 4 3 2 1
initial weight: 4 3 2 1
plus special weight:
id1: 4 3 2 1
initial weight: 4 3 2 1
id2: 1 2 3 4
special weight: 1 1 1 100 0 0 0 0 0 0
current weight: 5 4 3 101
sort by weight:
id1: 1 4 3 2
current weight: 101 5 4 3
select 3 fans:
[1,4,3]
See more examples in the sample tests.
Note
All indexs in description are 1-based.
3
fixed testcases100
random testcases, testing for correctness of solutionAll inputs are valid.
If my reference solution gives the wrong result in the random tests, please let me know(post an issue).
Similar Kata:
Stats:
Created | Nov 9, 2018 |
Published | Nov 9, 2018 |
Warriors Trained | 230 |
Total Skips | 29 |
Total Code Submissions | 302 |
Total Times Completed | 56 |
JavaScript Completions | 46 |
Haskell Completions | 7 |
Python Completions | 8 |
Total Stars | 5 |
% of votes with a positive feedback rating | 90% of 26 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |