> For the complete documentation index, see [llms.txt](https://jaywin.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaywin.gitbook.io/leetcode/solutions/1989-maximum-number-of-people-that-can-be-caught-in-tag.md).

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

<https://leetcode.com/problems/maximum-number-of-people-that-can-be-caught-in-tag>

## Description

You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are "it", and people who are not "it". The people who are "it" want to catch as many people as possible who are not "it".

You are given a **0-indexed** integer array `team` containing only zeros (denoting people who are **not** "it") and ones (denoting people who are "it"), and an integer `dist`. A person who is "it" at index `i` can catch any **one** person whose index is in the range `[i - dist, i + dist]` (**inclusive**) and is **not** "it".

Return *the **maximum** number of people that the people who are "it" can catch*.

**Example 1:**

```
**Input:** team = [0,1,0,1,0], dist = 3
**Output:** 2
**Explanation:**
The person who is "it" at index 1 can catch people in the range [i-dist, i+dist] = [1-3, 1+3] = [-2, 4].
They can catch the person who is not "it" at index 2.
The person who is "it" at index 3 can catch people in the range [i-dist, i+dist] = [3-3, 3+3] = [0, 6].
They can catch the person who is not "it" at index 0.
The person who is not "it" at index 4 will not be caught because the people at indices 1 and 3 are already catching one person.
```

**Example 2:**

```
**Input:** team = [1], dist = 1
**Output:** 0
**Explanation:**
There are no people who are not "it" to catch.
```

**Example 3:**

```
**Input:** team = [0], dist = 1
**Output:** 0
**Explanation:**There are no people who are "it" to catch people.
```

**Constraints:**

* `1 <= team.length <= 105`
* `0 <= team[i] <= 1`
* `1 <= dist <= team.length`

## ac

```java
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/1989-maximum-number-of-people-that-can-be-caught-in-tag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
