Tap here to switch tabs
Problem
Submissions

Problem: Longest Arithmetic Subsequence of Given Difference

med
30 min
Try to solve the Longest Arithmetic Subsequence of Given Difference problem.

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

med
30 min
Try to solve the Longest Arithmetic Subsequence of Given Difference problem.

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