MEDIUMasked at 1 company

Longest Arithmetic Subsequence

A medium-tier problem at 49% community acceptance, tagged with Array, Hash Table, Binary Search. Reported in interviews at Snapdeal and 0 others.

Founder's read

Longest Arithmetic Subsequence is a medium-difficulty problem that sits at the intersection of dynamic programming and hash tables. It shows up in assessments at companies like Snapdeal, and it's the kind of problem where the brute-force approach will time out or blow your stack. The trick isn't obvious on first read: you need to recognize that you're not building a single sequence, but tracking multiple arithmetic progressions in parallel as you iterate through the array. If this problem hits your live assessment and you blank on the DP formulation, StealthCoder solves it in seconds invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
49%

Companies that ask "Longest Arithmetic Subsequence"

If this hits your live OA

Longest Arithmetic Subsequence is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The problem asks for the longest subsequence (not necessarily contiguous) where consecutive elements have a constant difference. Most candidates start by thinking two pointers or sorting, which doesn't work because you need to preserve the array order. The winning pattern uses dynamic programming where you track every possible difference seen so far and how long the arithmetic sequence with that difference ending at the current element is. For each element, you check every prior element, compute their difference, and update a hash table mapping differences to sequence lengths. This avoids re-comparing all pairs and keeps your complexity manageable. The acceptance rate around 49 percent reflects that plenty of people solve it, but missed edge cases or suboptimal transitions cost points in real OAs. StealthCoder is your hedge if the state transition doesn't click during the assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Longest Arithmetic Subsequence recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Arithmetic Subsequence interview FAQ

Is this actually asked at FAANG or just smaller companies?+

This problem appears in real OAs, confirmed by Snapdeal reports. It's classic DP material and fits the medium-difficulty sweet spot interviewers use to separate prepared candidates from lucky ones. You'll see it more often at mid-size tech shops and startups than at household names, but the pattern (DP plus hash table) is universal.

What's the trick that makes this not just brute force?+

The trick is realizing you need to track the difference, not the elements. A hash table per index position maps 'difference' to 'longest sequence with that difference ending here'. When you process element i, you look back at all j < i, compute diff = arr[i] - arr[j], and update dp[i][diff]. This collapses O(n^3) brute force into O(n^2) with hash tables.

Do I need to know binary search for this problem?+

Binary search is listed in the topics but isn't required for the standard DP solution. It's possible a variant asks you to optimize further or there's an alternative approach, but the hash table plus DP path is the intended route. Don't over-engineer on test day.

What's the most common pitfall in a live coding session?+

Getting the DP transition wrong: forgetting to check if a prior difference exists before updating, or initializing sequence lengths to 2 instead of 1. Also, off-by-one errors when you try to optimize space. Write the two-array solution first, then optimize if you have time.

How does this relate to other DP problems I've seen?+

It's similar to longest increasing subsequence in structure (DP from every prior element), but instead of comparing values you're computing a property (the difference) and using that as a key. It bridges array DP and hash table design, which shows up in coin change and other medium problems.

Want the actual problem statement? View "Longest Arithmetic Subsequence" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.