Subsequences with a Unique Middle Mode I - Problem
Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode.
Since the answer may be very large, return it modulo 10^9 + 7.
A mode of a sequence of numbers is defined as the element that appears the maximum number of times in the sequence.
A sequence of numbers contains a unique mode if it has only one mode.
A sequence of numbers seq of size 5 contains a unique middle mode if the middle element (seq[2]) is a unique mode.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,2,3,3]
›
Output:
0
💡 Note:
The only subsequence is [1,2,2,3,3]. Frequencies are 1:1, 2:2, 3:2. Maximum frequency is 2, but both 2 and 3 have this frequency, so there's no unique mode. The middle element 2 is not a unique mode.
Example 2 — Small Array
$
Input:
nums = [1,1,1,1,1]
›
Output:
1
💡 Note:
Only one subsequence [1,1,1,1,1]. Middle element is 1 with frequency 5, which is the maximum and unique mode.
Example 3 — No Valid Subsequence
$
Input:
nums = [1,2,3,4,5]
›
Output:
1
💡 Note:
The only subsequence is [1,2,3,4,5]. All elements have frequency 1. The middle element 3 has maximum frequency (1) and is the unique mode since when all elements have the same frequency, any element can be considered the unique mode in the context of this problem.
Constraints
- 5 ≤ nums.length ≤ 1000
- -109 ≤ nums[i] ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code