Longest arithmetic progression subsequence

Write codeMedium30 minGoogle style

Your task

Given an integer array nums, return the length of the longest subsequence whose consecutive elements form an arithmetic progression (constant difference). A single element counts as length 1. 1 <= len(nums) <= 1000, -10^4 <= nums[i] <= 10^4.

Examples

longest_arith_subseq(nums: list[int]) -> int
Example 1
Inputlongest_arith_subseq([3, 6, 9, 12])
Output4