Count Good Subsequence
Reported by candidates from Flexport's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You're facing a Flexport OA in the next couple of days with a counting problem: Count Good Subsequence. This is a dynamic programming play, and the trap is misreading what makes a subsequence 'good'. The problem will define a constraint (sum, parity, modulo, or element relationship) that filters which subsequences count. If you blank during the live OA, StealthCoder reads the full constraint and gives you the DP recurrence on the spot. You're not building the subsequence itself, just counting valid ones.
Pattern and pitfall
The core pattern is memoized counting with a state that tracks progress toward the 'good' definition. You'll likely use DP where dp[index][state] = count of good subsequences ending at or considering index with a particular state value (sum mod k, running total, or constraint flag). The trick: recognize whether you're summing elements, checking differences, or tracking some modular property. Most candidates initially iterate all 2^n subsequences. You don't. You track the state incrementally and combine counts. Each element either gets included or skipped, and you update the count based on whether that choice keeps you valid. StealthCoder helps here by identifying the state variable instantly so you don't waste 10 minutes figuring out what to memoize.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Count Good Subsequence 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Flexport's OA.
Flexport reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Good Subsequence FAQ
What makes a subsequence 'good' in this problem?+
The OA will define it explicitly, likely a constraint on the sum, product, GCD, or some modular property of the elements. Read the definition carefully before coding. It's the single most common misread on this problem.
Is this a brute-force problem or DP?+
DP. Brute force (2^n enumeration) will time out. You need memoization or bottom-up DP to count valid subsequences efficiently. The state depends on what 'good' means.
How do I structure the DP state?+
Usually dp[index][constraint_state] where index is the position in the array and constraint_state tracks progress toward the 'good' definition. The second dimension size depends on the constraint. Start by identifying what you need to track to know if a subsequence is valid.
What's the time complexity I should aim for?+
O(n * state_space) in most cases. If state_space is bounded (like sum mod k or a small range), you're in the clear. If it grows unboundedly, re-examine the constraint. Flexport problems usually fit in 1-2 seconds with reasonable DP.
Will this problem ask for modulo in the answer?+
Possibly. If the count is very large, the OA will ask for the answer modulo 10^9+7 or similar. Apply the mod at every addition step to avoid overflow. Don't leave it until the end.