Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Solution: Longest Arithmetic Subsequence
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an array nums containing positive integers, return the maximum length of a subsequence that forms an arithmetic progression.

  • A subsequence is an array that can be formed from nums by 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 all 0 <= i < seq.length - 2.

Examples

  • Example 1:
    • Input: [8, 12, 6, 4, 2]

.....

.....

.....

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