Count Special Subsequences
You are given an array nums consisting of positive integers.
A special subsequence is defined as a subsequence of length 4, represented by indices (p, q, r, s), where p < q < r < s. This subsequence must satisfy the following conditions:
nums[p] * nums[r] == nums[q] * nums[s]- There must be at least one element between each pair of indices. In other words,
q - p > 1,r - q > 1, ands - r > 1.
Return the number of different special subsequences in nums.
Example 1
Input
nums = [1,2,3,4,3,6,1]Output
1The only special subsequence is at indices
(0, 2, 4, 6), where the products are both 3.Example 2
Input
nums = [3,4,3,4,3,4,3,4]Output
3There are three valid index quadruples:
(0, 2, 4, 6), (1, 3, 5, 7), and (0, 2, 5, 7).Constraints
- 7 <= nums.length <= 1000
- 1 <= nums[i] <= 1000