3395. Subsequences with a Unique Middle Mode I Hard

@problem@discussion
#Array#Hash Table#Math#Combinatorics



1/**
2 * [3395] Subsequences with a Unique Middle Mode I
3 *
4 * Given an integer array nums, find the number of <span data-keyword="subsequence-array">subsequences</span> of size 5 of nums with a unique middle mode.
5 * Since the answer may be very large, return it modulo 10^9 + 7.
6 * A mode of a sequence of numbers is defined as the element that appears the maximum number of times in the sequence.
7 * A sequence of numbers contains a unique mode if it has only one mode.
8 * A sequence of numbers seq of size 5 contains a unique middle mode if the middle element (seq[2]) is a unique mode.
9 *  
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">nums = [1,1,1,1,1,1]</span>
13 * Output: <span class="example-io">6</span>
14 * Explanation:
15 * [1, 1, 1, 1, 1] is the only subsequence of size 5 that can be formed, and it has a unique middle mode of 1. This subsequence can be formed in 6 different ways, so the output is 6. 
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">nums = [1,2,2,3,3,4]</span>
20 * Output: <span class="example-io">4</span>
21 * Explanation:
22 * [1, 2, 2, 3, 4] and [1, 2, 3, 3, 4] each have a unique middle mode because the number at index 2 has the greatest frequency in the subsequence. [1, 2, 2, 3, 3] does not have a unique middle mode because 2 and 3 appear twice.
23 * </div>
24 * <strong class="example">Example 3:
25 * <div class="example-block">
26 * Input: <span class="example-io">nums = [0,1,2,3,4,5,6,7,8]</span>
27 * Output: <span class="example-io">0</span>
28 * Explanation:
29 * There is no subsequence of length 5 with a unique middle mode.
30 * </div>
31 *  
32 * Constraints:
33 * 
34 * 	5 <= nums.length <= 1000
35 * 	<font face="monospace">-10^9 <= nums[i] <= 10^9</font>
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/subsequences-with-a-unique-middle-mode-i/
41// discuss: https://leetcode.com/problems/subsequences-with-a-unique-middle-mode-i/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn subsequences_with_middle_mode(nums: Vec<i32>) -> i32 {
47        0
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_3395() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.