Arithmetic Slices II - Subsequence
A hard-tier problem at 55% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at Baidu and 1 others.
Arithmetic Slices II hits different because it's not about contiguous subarrays. You're hunting for subsequences of length 3 or more where the difference between consecutive elements stays constant. Baidu and Dunzo have both asked it, and the 54.5% acceptance rate tells you the obvious DP approach will trip you up. Most candidates iterate through pairs and miss the state compression that actually scales, or they overcomplicate the memoization. If this problem shows up in your assessment and you blank on the trick, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Arithmetic Slices II - Subsequence"
Arithmetic Slices II - 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. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe trap is thinking you need to track every possible subsequence explicitly. You don't. The key insight: for each ending position, store a map of differences to counts. When you process element at index i, for each prior element at index j, the difference is arr[i] - arr[j]. If that difference already exists in j's map, you extend all subsequences ending at j with that difference. This is where DP state compression saves you from exponential blowup. Common failure: forgetting to count new arithmetic sequences of length exactly 3 separately, or not handling the difference map transitions correctly across iterations. The pattern requires both Array awareness and Dynamic Programming discipline. StealthCoder is your hedge for the live OA if the state transition logic doesn't click under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Arithmetic Slices II - Subsequence recycles across companies for a reason. It's hard-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. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Arithmetic Slices II - Subsequence interview FAQ
Is this actually harder than Arithmetic Slices I?+
Yes. Part I is contiguous, so greedy or simple DP works. Part II requires subsequences, which means you must track differences per element and avoid counting duplicates. The state space is nonobvious. The 54.5% acceptance rate reflects that jump in complexity.
What's the trick nobody gets right the first time?+
Not realizing you need a map of differences for each index, not a single global counter. You iterate through all prior elements, compute the difference, extend existing arithmetic sequences, and seed new ones. Getting the map update order and initialization wrong is the most common pitfall.
How much space do I actually need?+
O(n) indices, each with a map of differences. In worst case, O(n^2) space total. That's acceptable for most constraints. The time is O(n^2) because you check all pairs. Don't try to optimize space before correctness.
Is this still asked at Baidu and Dunzo?+
Yes, both are in the reported list. It's not as common as easier DP problems, but it's a strong signal for mid-to-senior level roles. Expect it as a hard problem, not a warm-up.
How does this relate to the Array and DP topics?+
The Array part is just iteration and indexing. The real challenge is DP: defining the state (difference maps per index), transition (extending prior sequences), and base case (length-3 sequences). It's a textbook example of state compression in DP.
Want the actual problem statement? View "Arithmetic Slices II - Subsequence" on LeetCode →