1989. Maximum Number of People That Can Be Caught in Tag

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1989

class Solution:
    def catchMaximumAmountofPeople(self, team: List[int], dist: int) -> int:
        res = j = 0
        n = len(team)
        for i, x in enumerate(team):
            if x:
                while j < n and (team[j] or i - j > dist):
                    j += 1
                if j < n and abs(i - j) <= dist:
                    res += 1
                    j += 1
        return res