Find Longest Chain
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg's September OA threw this at real candidates: find the longest chain where you can pick pairs and link them together based on some constraint. You've got 24-72 hours and the problem text didn't leak verbatim, but the pattern is classic dynamic programming. The trap is thinking greedy works when you actually need to build up solutions from smaller subproblems. StealthCoder catches the moment you freeze on recurrence relations during the live assessment.
Pattern and pitfall
This is a DP sequencing problem, likely involving weighted intervals or pair dependencies. The instinct is to sort and greedily pick. Wrong. You need to compute the longest chain ending at each state, then trace back the max. The recurrence usually looks like: dp[i] = 1 + max(dp[j]) where j is any valid predecessor of i, or dp[i] = 1 if no predecessor exists. The gotcha is recognizing what makes a valid predecessor and building the dependency graph correctly before you code. StealthCoder reads the problem on screen and walks you through the DP state definition so you don't blank on the recurrence structure when you're live.
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 Longest Chain 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
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg 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 Longest Chain FAQ
Is this just a greedy sort-and-pick problem?+
No. Greedy fails because picking the smallest pair locally can block longer chains globally. You need DP to explore all valid predecessor states. The length of the final answer is always at least as large as the greedy solution, often larger.
What's the state definition I should start with?+
dp[i] = longest chain ending with the i-th element. Then iterate backwards and check which earlier elements are valid predecessors. The answer is the max value in the DP array.
How do I know if one pair can link to another?+
The problem likely defines this via numerical inequality or direct attributes. Read the constraint carefully. Common: pair A can precede pair B if A's second value is strictly less than B's first value, or similar. The constraint is everything.
Can I solve this in one pass without sorting?+
Not efficiently. Sort by the first element of each pair (or second element, depending on the constraint). Then DP in sorted order so you always check valid predecessors before computing the current state.
How do I prepare for this in 48 hours?+
Recognize the pattern: you have items with two attributes, you need to chain them, answer is a count. That's DP on weighted intervals. Code one classic interval DP problem (like weighted job scheduling) so the recurrence feels familiar when you see it live.