-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm32.js
More file actions
29 lines (27 loc) · 821 Bytes
/
algorithm32.js
File metadata and controls
29 lines (27 loc) · 821 Bytes
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
function solution(N, stages) {
var answer = [];
let [cleared, reached] = [new Array(N).fill(0), new Array(N).fill(0)]
stages.map(v => {
if(v === N+1){
for(let i=0; i< v-1; i++){
reached[i] += 1
cleared[i] += 1
}
} else {
for(let i=0; i< v; i++){
reached[i] += 1
}
for(let i=0; i< v-1; i++){
cleared[i] += 1
}
}
})
let failure = cleared.map((v, i) => (reached[i]-v)/reached[i])
let seq_arr = Array.from({length: N}, (_,i)=>i+1)
let res = new Map()
for(let i=0; i<failure.length; i++){
res.set(seq_arr[i], failure[i])
}
answer = [...new Map([...res].sort((a, b) => b[1]-a[1])).keys()]
return answer;
}