Longest Subsequence With Decreasing Adjacent Difference
A medium-tier problem at 15% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at Juspay and 0 others.
You're staring at a medium difficulty problem with a 14% acceptance rate. Juspay has asked this. The premise sounds straightforward: find the longest subsequence where the difference between adjacent elements keeps decreasing. The trick is that most candidates see dynamic programming and immediately think of the obvious state definition, which doesn't scale or doesn't capture the constraint correctly. You need to track not just position and length, but the previous difference itself. That's where the pattern breaks open, and that's where most people get stuck in a real OA. If this problem hits your assessment and you blank on how to encode the state, StealthCoder surfaces a working solution invisibly.
Companies that ask "Longest Subsequence With Decreasing Adjacent Difference"
Longest Subsequence With Decreasing Adjacent Difference 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 by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe core insight is that you can't just track dp[i] = longest subsequence ending at index i. You need dp[i][diff] = longest subsequence ending at index i where the last adjacent difference was diff. This forces you to iterate through all pairs and maintain the constraint that each new difference is strictly smaller than the previous one. The array and dynamic programming topics combine here in a way that feels unusual because the DP state depends on a value, not just a position. Most candidates either miss that the difference itself must be part of the state, or they implement it inefficiently and hit time limits. The constraint that differences must be strictly decreasing makes greedy approaches fail. If you haven't drilled this exact pattern before, it's easy to burn 20 minutes on a dead end. That's the spot where StealthCoder becomes your safety net during the live assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Longest Subsequence With Decreasing Adjacent Difference 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 by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Subsequence With Decreasing Adjacent Difference interview FAQ
Why can't I just use dp[i] = longest subsequence ending at i?+
Because the constraint isn't just about which elements you pick. It's about the differences between consecutive picked elements being strictly decreasing. You need to know what the last difference was to decide if a new element can extend the subsequence. Without that in your state, you can't enforce the constraint.
Is this really a medium problem, or is 14% acceptance rate a red flag?+
The low acceptance rate reflects that the state definition isn't obvious. Once you realize you need to track the previous difference, the DP logic is straightforward. It's medium because the insight is pattern-based, not because the code is complex. You either see it or you don't.
How does this relate to other DP on arrays problems I've seen?+
Most array DP problems track position or count. This one also tracks a derived value (the difference). It's closer to problems where you cache relationships between elements, not just their indices. That's the unusual part that trips people up.
What's the time complexity trap?+
If you naively store every possible difference as a separate state, you can blow up memory and time. You need to be smart about which differences you actually track, typically using a hash map or dictionary instead of a full DP table to avoid storing impossible states.
Has Juspay asked this recently, or is it old data?+
The input shows Juspay as the reported company. You can't assume recency from the data, but if you're interviewing there, this pattern is in their pool. It's worth understanding the state-definition trick even if this exact problem doesn't come up.
Want the actual problem statement? View "Longest Subsequence With Decreasing Adjacent Difference" on LeetCode →