Skip to content

Commit 46773b8

Browse files
authored
Create 1921-eliminate-maximum-number-of-monsters.js
1 parent e650410 commit 46773b8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Greedy | Sorting
3+
* Time O(n*log(n)) | Space O(n)
4+
* @param {number[]} dist
5+
* @param {number[]} speed
6+
* @return {number}
7+
*/
8+
var eliminateMaximum = function(dist, speed) {
9+
10+
const time = dist.map((d, i) => {
11+
return d / speed[i];
12+
});
13+
14+
let monsterSlyed = 1;
15+
time.sort((a,b) => a-b);
16+
for(let i = 1; i < time.length; i++) {
17+
if(time[i] <= monsterSlyed) return monsterSlyed;
18+
monsterSlyed++;
19+
}
20+
21+
return monsterSlyed;
22+
};

0 commit comments

Comments
 (0)