Free written solutionLongest Arithmetic Subsequence of Given Difference (LeetCode 1218): Solution and Explanation
Given an array and a fixed step called difference, find the longest subsequence where each element equals the previous one plus difference. Return its length; a single element always counts as length 1.
Read the intuition, approach, code and complexity →