Tap here to switch tabs
Problem
Submissions

Problem: Longest Arithmetic Subsequence of Given Difference

Longest Arithmetic Subsequence of Given Difference asks you to find the length of a subsequence in an integer array whose consecutive values differ by the given amount while preserving their order.

Statement

Given an integer array arr and an integer difference, find the length of the longest arithmetic subsequence in arr such that the difference between any two consecutive elements in the subsequence is equal to difference.

A subsequence is a sequence derived from arr by deleting zero or more elements without changing the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq arr.length ≤105\leq 10^5

  • −104≤-10^4 \leq arr[i], difference ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Arithmetic Subsequence of Given Difference

Longest Arithmetic Subsequence of Given Difference asks you to find the length of a subsequence in an integer array whose consecutive values differ by the given amount while preserving their order.

Statement

Given an integer array arr and an integer difference, find the length of the longest arithmetic subsequence in arr such that the difference between any two consecutive elements in the subsequence is equal to difference.

A subsequence is a sequence derived from arr by deleting zero or more elements without changing the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq arr.length ≤105\leq 10^5

  • −104≤-10^4 \leq arr[i], difference ≤104\leq 10^4