Find the Max Len of A Good Subsequence I
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Snowflake's December OA is asking you to find the maximum length of a 'good' subsequence. The problem is vague on purpose, which means the interviewer expects you to reverse-engineer the definition from examples or constraints. This is a dynamic programming problem dressed up in loose language. If you blank on the DP state transition, StealthCoder will feed you the pattern in real time so you don't waste 20 minutes guessing what 'good' means.
Pattern and pitfall
This problem hinges on defining what makes a subsequence 'good'. Typically, Snowflake will embed a numerical constraint: adjacent elements in the subsequence satisfy some property (difference, modulo, absolute value, or sum). The classic DP approach is to track the maximum length ending at each position, then reconsider all prior positions to see which ones could legally extend. The pitfall is misreading the constraint and building a state that's either impossible to compute or doesn't actually enforce 'good'. Common mistakes include treating it as greedy (it's not) or missing that order matters. When the test runs live, you'll see examples that clarify the rule. StealthCoder reads those examples and helps you translate them into the DP recurrence before you get stuck.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Find the Max Len of A Good Subsequence I cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as longest increasing subsequence. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find the Max Len of A Good Subsequence I FAQ
What does 'good subsequence' mean if the problem doesn't spell it out?+
The test will have examples that show the rule implicitly. Usually it's something like 'adjacent elements differ by at most k' or 'the sum of consecutive pairs stays even.' Read the examples first, not the vague English. Write down what the first 'good' example satisfies, then check against a bad one.
Is this a greedy problem or DP?+
It's DP. Greedy fails because you can't always extend the longest good subsequence so far. You need to track all possible endings and branch. Standard O(n squared) or O(n log n) depending on the constraint structure.
How do I define the DP state?+
dp[i] = maximum length of a good subsequence ending at index i. For each i, loop back through j < i, check if extending j to i is legal, then dp[i] = max(dp[i], dp[j] + 1). Initialization: dp[i] = 1 for all i (a single element is always good).
What's the common pitfall in reading the constraint?+
Candidates often confuse 'adjacent in the subsequence' with 'adjacent in the original array.' If the subsequence is indices [0, 2, 5], then elements at 0 and 2 are adjacent in the subsequence, not 0 and 1. Re-read the examples to confirm.
Can I solve this in 2-3 minutes under pressure?+
No, not from scratch. You'll need to read examples, confirm the constraint, write the DP loop, and test. Aim for 10-15 minutes. If you blank on the state transition, that's when you use your safety net to unblock fast.