You're given an integer array nums, and your task is to find the number of subsequences of size 5 where the middle element (3rd position) is the unique mode of that subsequence.
What's a mode? The mode is the element that appears most frequently in a sequence. A unique mode means there's exactly one element that appears more frequently than all others.
What's a unique middle mode? In a 5-element subsequence [a, b, c, d, e], element c (middle) must be the unique mode - it appears more times than any other element in those 5 positions.
Goal: Count all such valid subsequences. Since the answer can be very large, return it modulo 109 + 7.
Example: If nums = [1,2,1,2,1], the subsequence [1,2,1,2,1] has 1 as the middle element, and 1 appears 3 times while 2 appears 2 times, so 1 is the unique mode.
Input & Output
Constraints
- 5 โค nums.length โค 1000
- 1 โค nums[i] โค 1000
- The middle element must have strictly higher frequency than any other element in the subsequence