-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
comments: true | ||
difficulty: 困难 | ||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README.md | ||
--- | ||
|
||
<!-- problem:start --> | ||
|
||
# [3416. Subsequences with a Unique Middle Mode II 🔒](https://leetcode.cn/problems/subsequences-with-a-unique-middle-mode-ii) | ||
|
||
[English Version](/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- description:start --> | ||
|
||
<p>Given an integer array <code>nums</code>, find the number of <span data-keyword="subsequence-array">subsequences</span> of size 5 of <code>nums</code> with a <strong>unique middle mode</strong>.</p> | ||
|
||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> | ||
|
||
<p>A <strong>mode</strong> of a sequence of numbers is defined as the element that appears the <strong>maximum</strong> number of times in the sequence.</p> | ||
|
||
<p>A sequence of numbers contains a<strong> unique mode</strong> if it has only one mode.</p> | ||
|
||
<p>A sequence of numbers <code>seq</code> of size 5 contains a <strong>unique middle mode</strong> if the <em>middle element</em> (<code>seq[2]</code>) is a <strong>unique mode</strong>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<p><strong>Input:</strong> nums = [1,1,1,1,1,1]</p> | ||
|
||
<p><strong>Output:</strong> 6</p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<p><code>[1, 1, 1, 1, 1]</code> is the only subsequence of size 5 that can be formed from this list, and it has a unique middle mode of 1.</p> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<p><strong>Input:</strong> nums = [1,2,2,3,3,4]</p> | ||
|
||
<p><strong>Output:</strong> 4</p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<p><code>[1, 2, 2, 3, 4]</code> and <code>[1, 2, 3, 3, 4]</code> have unique middle modes because the number at index 2 has the greatest frequency in the subsequence. <code>[1, 2, 2, 3, 3]</code> does not have a unique middle mode because 2 and 3 both appear twice in the subsequence.</p> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<p><strong>Input:</strong> nums = [0,1,2,3,4,5,6,7,8]</p> | ||
|
||
<p><strong>Output:</strong> 0</p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<p>There does not exist a subsequence of length 5 with a unique middle mode.</p> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>5 <= nums.length <= 10<sup>5</sup></code></li> | ||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> | ||
</ul> | ||
|
||
<!-- description:end --> | ||
|
||
## 解法 | ||
|
||
<!-- solution:start --> | ||
|
||
### 方法一 | ||
|
||
<!-- tabs:start --> | ||
|
||
#### Python3 | ||
|
||
```python | ||
|
||
``` | ||
|
||
#### Java | ||
|
||
```java | ||
|
||
``` | ||
|
||
#### C++ | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
#### Go | ||
|
||
```go | ||
|
||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- solution:end --> | ||
|
||
<!-- problem:end --> |
104 changes: 104 additions & 0 deletions
104
solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README_EN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
comments: true | ||
difficulty: Hard | ||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README_EN.md | ||
--- | ||
|
||
<!-- problem:start --> | ||
|
||
# [3416. Subsequences with a Unique Middle Mode II 🔒](https://leetcode.com/problems/subsequences-with-a-unique-middle-mode-ii) | ||
|
||
[中文文档](/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README.md) | ||
|
||
## Description | ||
|
||
<!-- description:start --> | ||
|
||
<p>Given an integer array <code>nums</code>, find the number of <span data-keyword="subsequence-array">subsequences</span> of size 5 of <code>nums</code> with a <strong>unique middle mode</strong>.</p> | ||
|
||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> | ||
|
||
<p>A <strong>mode</strong> of a sequence of numbers is defined as the element that appears the <strong>maximum</strong> number of times in the sequence.</p> | ||
|
||
<p>A sequence of numbers contains a<strong> unique mode</strong> if it has only one mode.</p> | ||
|
||
<p>A sequence of numbers <code>seq</code> of size 5 contains a <strong>unique middle mode</strong> if the <em>middle element</em> (<code>seq[2]</code>) is a <strong>unique mode</strong>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<p><strong>Input:</strong> nums = [1,1,1,1,1,1]</p> | ||
|
||
<p><strong>Output:</strong> 6</p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<p><code>[1, 1, 1, 1, 1]</code> is the only subsequence of size 5 that can be formed from this list, and it has a unique middle mode of 1.</p> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<p><strong>Input:</strong> nums = [1,2,2,3,3,4]</p> | ||
|
||
<p><strong>Output:</strong> 4</p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<p><code>[1, 2, 2, 3, 4]</code> and <code>[1, 2, 3, 3, 4]</code> have unique middle modes because the number at index 2 has the greatest frequency in the subsequence. <code>[1, 2, 2, 3, 3]</code> does not have a unique middle mode because 2 and 3 both appear twice in the subsequence.</p> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<p><strong>Input:</strong> nums = [0,1,2,3,4,5,6,7,8]</p> | ||
|
||
<p><strong>Output:</strong> 0</p> | ||
|
||
<p><strong>Explanation:</strong></p> | ||
|
||
<p>There does not exist a subsequence of length 5 with a unique middle mode.</p> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>5 <= nums.length <= 10<sup>5</sup></code></li> | ||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> | ||
</ul> | ||
|
||
<!-- description:end --> | ||
|
||
## Solutions | ||
|
||
<!-- solution:start --> | ||
|
||
### Solution 1 | ||
|
||
<!-- tabs:start --> | ||
|
||
#### Python3 | ||
|
||
```python | ||
|
||
``` | ||
|
||
#### Java | ||
|
||
```java | ||
|
||
``` | ||
|
||
#### C++ | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
#### Go | ||
|
||
```go | ||
|
||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- solution:end --> | ||
|
||
<!-- problem:end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters