-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclimbing-the-leaderboard.js
48 lines (41 loc) · 1.19 KB
/
climbing-the-leaderboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function climbingLeaderboard(scores, alice) {
// Complete this function
let scoresNR = [...new Set(scores)];
let rank = scoresNR.length - 1;
let results = [];
for (let i = 0; i < alice.length; i++) {
while (alice[i] > scoresNR[rank] && rank > 0) rank--;
if (alice[i] >= scoresNR[rank]) {
results.push(rank + 1);
} else {
results.push(rank + 2);
}
}
return results;
}
function main() {
var n = parseInt(readLine());
scores = readLine().split(' ');
scores = scores.map(Number);
var m = parseInt(readLine());
alice = readLine().split(' ');
alice = alice.map(Number);
var result = climbingLeaderboard(scores, alice);
console.log(result.join("\n"));
}