Problem Solving/LeetCode

2023.11.09 Today's Challenge

fabichoi 2023. 11. 9. 23:45

https://leetcode.com/problems/eliminate-maximum-number-of-monsters/?envType=daily-question&envId=2023-11-07

 

Eliminate Maximum Number of Monsters - LeetCode

Can you solve this real interview question? Eliminate Maximum Number of Monsters - You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initi

leetcode.com

순차적으로 시뮬레이션을 해보았으나 계속 실패 ㅠ
솔루션 보니, 평균값을 구해서 답을 찾는 방법이 있었음...

class Solution:
    def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int:
        arv = sorted([dist[i]/speed[i] for i in range(len(dist))])
        ans = 0
        for i in range(len(arv)):
            if arv[i] <= i:
                break
            ans += 1
        return ans
반응형