Back to course home
0% completed
Vote For New Content
Longest Arithmetic Subsequence (medium)
Problem Statement
Given an array nums containing positive integers, return the maximum length of a subsequence that forms an arithmetic progression.
-
A
subsequenceis an array that can be formed fromnumsby deleting 0 or more elements without changing the order of the remaining elements. -
An arithmetic progression (AP) is a sequence of numbers in which the difference between any two consecutive elements is constant. In short,
seq[i + 1] - seq[i]should be same for all0 <= i < seq.length - 2.
Examples
- Example 1:
- Input:
[8, 12, 6, 4, 2]
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible