Algorithm · C3.ai · Hard
You are given an array of integers nums. Determine the length of the longest arithmetic subsequence it contains, that is, the longest subsequence in which the difference between every pair of adjacent elements is the same value. A subsequence is formed by deleting zero or more elements from nums without rearranging the elements that remain, so the chosen elements must appear in their original relative order but need not be contiguous. Examples Example 1 Example 2