Description
An arithmetic subsequence has at least 3 elements with constant difference. Return the number of arithmetic subsequences in the array.
Examples
Input:
nums = [2,4,6,8,10]Output:
7Explanation:
7 arithmetic subsequences exist.
Input:
nums = [1]Output:
1Explanation:
Edge case with a single-element array.
Input:
nums = [7,7,7,7]Output:
4Explanation:
All elements are equal, so the common difference is 0. Arithmetic subsequences of length 3+: [7,7,7] at positions (0,1,2), (0,1,3), (0,2,3), (1,2,3), and [7,7,7,7] using all positions. Total: 5.
Constraints
- •
1 ≤ nums.length ≤ 1000 - •
-2³¹ ≤ nums[i] ≤ 2³¹ - 1