Practice Longest Arithmetic Subsequence
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#1027
LeetCode ProblemLongest Arithmetic Subsequence
Problem Statement
Return the length of the longest arithmetic subsequence of nums. A subsequence retains the original order while optionally deleting elements. It is arithmetic when the difference between every pair of consecutive retained elements is the same.
Source: Longest Arithmetic Subsequence on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [3,6,9,12]
Output
4
# Example 2
Input
nums = [9,4,7,2,10]
Output
3
# Example 3
Input
nums = [20,1,15,3,10,5,8]
Output
4
Constraints
2 <= nums.length <= 1000
0 <= nums[i] <= 500
Related LeetCode Problems
Practice more problems similar to Longest Arithmetic Subsequence.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.