#3404

Count Special Subsequences

expert · 1130 · lc medium +32 · 29.8% accepted · 193 likes · top 7%

Description

You are given an array nums of positive integers.

A special subsequence has length 4 and uses indices (p, q, r, s) where p < q < r < s, satisfying:

- nums[p] * nums[r] == nums[q] * nums[s]

- Consecutive indices differ by more than 1: q - p > 1, r - q > 1, and s - r > 1.

Return the count of distinct special subsequences in nums.

Code

1
2
3