|
| 1 | +--- |
| 2 | +comments: true |
| 3 | +difficulty: 中等 |
| 4 | +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3893.Maximum%20Team%20Size%20with%20Overlapping%20Intervals/README.md |
| 5 | +--- |
| 6 | + |
| 7 | +<!-- problem:start --> |
| 8 | + |
| 9 | +# [3893. Maximum Team Size with Overlapping Intervals 🔒](https://leetcode.cn/problems/maximum-team-size-with-overlapping-intervals) |
| 10 | + |
| 11 | +[English Version](/solution/3800-3899/3893.Maximum%20Team%20Size%20with%20Overlapping%20Intervals/README_EN.md) |
| 12 | + |
| 13 | +## 题目描述 |
| 14 | + |
| 15 | +<!-- description:start --> |
| 16 | + |
| 17 | +<p data-end="767" data-start="694">You are given two integer arrays <code>startTime</code> and <code>endTime</code> of length <code>n</code>.</p> |
| 18 | + |
| 19 | +<ul> |
| 20 | + <li><code>startTime[i]</code> represents the start time of the <code>i<sup>th</sup></code> employee.</li> |
| 21 | + <li><code>endTime[i]</code> represents the end time of the <code>i<sup>th</sup></code> employee.</li> |
| 22 | +</ul> |
| 23 | + |
| 24 | +<p>Two employees <code>i</code> and <code>j</code> can interact if their time intervals <strong>overlap</strong>. Two intervals are considered overlapping if they share <strong>at least one</strong> common time point.</p> |
| 25 | + |
| 26 | +<p>A team is <strong>valid</strong> if there exists <strong>at least one</strong> employee in the team who can interact with every other member of the team.</p> |
| 27 | + |
| 28 | +<p>Return an integer denoting the <strong>maximum</strong> possible size of such a team.</p> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong class="example">Example 1:</strong></p> |
| 32 | + |
| 33 | +<div class="example-block"> |
| 34 | +<p><strong>Input:</strong> <span class="example-io">startTime = [1,2,3], endTime = [4,5,6]</span></p> |
| 35 | + |
| 36 | +<p><strong>Output:</strong> <span class="example-io">3</span></p> |
| 37 | + |
| 38 | +<p><strong>Explanation:</strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li>For <code>i = 0</code> with interval <code>[1, 4]</code>.</li> |
| 42 | + <li>It overlaps with <code>i = 1</code> having interval <code>[2, 5]</code> and <code>i = 2</code> having interval <code>[3, 6]</code>.</li> |
| 43 | + <li>Thus, index 0 can interact with all other indices, so the team size is 3.</li> |
| 44 | +</ul> |
| 45 | +</div> |
| 46 | + |
| 47 | +<p><strong class="example">Example 2:</strong></p> |
| 48 | + |
| 49 | +<div class="example-block"> |
| 50 | +<p><strong>Input:</strong> <span class="example-io">startTime = [2,5,8], endTime = [3,7,9]</span></p> |
| 51 | + |
| 52 | +<p><strong>Output:</strong> <span class="example-io">1</span></p> |
| 53 | + |
| 54 | +<p><strong>Explanation:</strong></p> |
| 55 | + |
| 56 | +<ul> |
| 57 | + <li>For <code>i = 0</code>, interval <code>[2, 3]</code> does not overlap with <code>[5, 7]</code> or <code>[8, 9]</code>.</li> |
| 58 | + <li>For <code>i = 1</code>, interval <code>[5, 7]</code> does not overlap with <code>[2, 3]</code> or <code>[8, 9]</code>.</li> |
| 59 | + <li>For <code>i = 2</code>, interval <code>[8, 9]</code> does not overlap with <code>[2, 3]</code> or <code>[5, 7]</code>.</li> |
| 60 | + <li>Thus, no index can interact with others, so the maximum team size is 1.</li> |
| 61 | +</ul> |
| 62 | +</div> |
| 63 | + |
| 64 | +<p><strong class="example">Example 3:</strong></p> |
| 65 | + |
| 66 | +<div class="example-block"> |
| 67 | +<p><strong>Input:</strong> <span class="example-io">startTime = [3,4,6], endTime = [8,5,7]</span></p> |
| 68 | + |
| 69 | +<p><strong>Output:</strong> <span class="example-io">3</span></p> |
| 70 | + |
| 71 | +<p><strong>Explanation:</strong></p> |
| 72 | + |
| 73 | +<ul> |
| 74 | + <li>For <code>i = 0</code> with interval <code>[3, 8]</code>.</li> |
| 75 | + <li>It overlaps with <code>i = 1</code> having interval <code>[4, 5]</code> and <code>i = 2</code> having interval <code>[6, 7]</code>.</li> |
| 76 | + <li>Thus, index 0 can interact with all other indices, so the team size is 3.</li> |
| 77 | +</ul> |
| 78 | +</div> |
| 79 | + |
| 80 | +<p> </p> |
| 81 | +<p><strong>Constraints:</strong></p> |
| 82 | + |
| 83 | +<ul> |
| 84 | + <li><code>1 <= n == startTime.length == endTime.length <= 10<sup>5</sup></code></li> |
| 85 | + <li><code>0 <= startTime[i] <= endTime[i] <= 10<sup>9</sup></code></li> |
| 86 | +</ul> |
| 87 | + |
| 88 | +<!-- description:end --> |
| 89 | + |
| 90 | +## 解法 |
| 91 | + |
| 92 | +<!-- solution:start --> |
| 93 | + |
| 94 | +### 方法一 |
| 95 | + |
| 96 | +<!-- tabs:start --> |
| 97 | + |
| 98 | +#### Python3 |
| 99 | + |
| 100 | +```python |
| 101 | + |
| 102 | +``` |
| 103 | + |
| 104 | +#### Java |
| 105 | + |
| 106 | +```java |
| 107 | + |
| 108 | +``` |
| 109 | + |
| 110 | +#### C++ |
| 111 | + |
| 112 | +```cpp |
| 113 | + |
| 114 | +``` |
| 115 | + |
| 116 | +#### Go |
| 117 | + |
| 118 | +```go |
| 119 | + |
| 120 | +``` |
| 121 | + |
| 122 | +<!-- tabs:end --> |
| 123 | + |
| 124 | +<!-- solution:end --> |
| 125 | + |
| 126 | +<!-- problem:end --> |
0 commit comments