Class Solution
-
- All Implemented Interfaces:
public final class Solution3404 - Count Special Subsequences.
Medium
You are given an array
numsconsisting of positive integers.A special subsequence is defined as a subsequence of length 4, represented by indices
(p, q, r, s), wherep < 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 > 1ands - r > 1.
A subsequence is a sequence derived from the array by deleting zero or more elements without changing the order of the remaining elements.
Return the number of different special subsequences in
nums.Example 1:
Input: nums = 1,2,3,4,3,6,1
Output: 1
Explanation:
There is one special subsequence in
nums.(p, q, r, s) = (0, 2, 4, 6):
Example 2:
Input: nums = 3,4,3,4,3,4,3,4
Output: 3
Explanation:
There are three special subsequences in
nums.(p, q, r, s) = (0, 2, 4, 6):(p, q, r, s) = (1, 3, 5, 7):(p, q, r, s) = (0, 2, 5, 7):
Constraints:
7 <= nums.length <= 10001 <= nums[i] <= 1000
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongnumberOfSubsequences(IntArray nums)-
-
Method Detail
-
numberOfSubsequences
final Long numberOfSubsequences(IntArray nums)
-
-
-
-