Reported July 2024
Benchlingdepth first search

Generate All Contiguous Protein Chains

Reported by candidates from Benchling's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Benchling OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt at Benchling's "Generate All Contiguous Protein Chains" is stopping at pairs. This one was reported in July 2024, and it's a DAG path enumeration problem dressed up as biology. Every sequence is a node, an edge exists when one end equals another start, and you emit every path of length one or more. Sorting the strings at the end is where people lose points. If you blank on the exact format mid-assessment, StealthCoder runs invisibly as a safety net. Know the shape before you open the invite.

The problem

Each named gene sequence has a half-open interval [start,end). A protein chain may begin at any sequence and append another sequence whenever the next start equals the current end.
Return every non-empty contiguous chain as joined_names:start:end, sorted lexicographically. Each interval strictly advances, so the sequence graph is acyclic.
Interview follow-up
A candidate was also asked how to incorporate newly added sequences into the existing result without naively rerunning full enumeration. Discuss updating endpoint indexes and generating only chains containing at least one new sequence, including chains that contain several new sequences. Account for duplicate discoveries and the unavoidable cost of emitting new results. The judged function performs initial enumeration.

Function
generateAllProteins(names: String[], ranges: int[][]) → String[]

Examples
Example 1
names = ["acG","Bf5","e5c","6a5d","7f6c","0Pf","0f5c"]
ranges = [[0,5],[0,22],[5,16],[5,17],[2,13],[13,23],[0,13]]
return = ["0Pf:13:23","0f5c:0:13","0f5c_0Pf:0:23","6a5d:5:17","7f6c:2:13","7f6c_0Pf:2:23","Bf5:0:22","acG:0:5","acG_6a5d:0:17","acG_e5c:0:16","e5c:5:16"]
Every input sequence is a protein, plus each chain whose endpoints touch.

Constraints
Names are unique.
1 <= names.length <= 15.
names.length == ranges.length.
0 <= start < end <= 10^9.
The number of output chains is at most 10000.
For this exercise, assume every sequence name contains only ASCII characters; an empty name is permitted. Lexicographic order compares these ASCII characters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is DFS from every sequence. Build a map from start value to the list of sequences beginning there. From each node, record the current chain, then recurse into every sequence whose start equals the current end. Each chain is emitted once, because a path has one starting node and one route. The pitfall is sorting. Sort the final output strings directly, not the name lists. Names can contain underscores and the format is joined_names:start:end, so ordering by raw ASCII comparison of the whole string matters. Also watch the empty name case, since joining can produce odd strings. Output is capped at 10000, so plain recursion is fine with at most 15 sequences. The follow-up about new sequences is discussion only. Index by start and end, then run DFS only through paths touching a new node. StealthCoder is your hedge if the live OA scrambles the join format under pressure.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Generate All Contiguous Protein Chains 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 StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Benchling's OA.

Benchling 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.

Generate All Contiguous Protein Chains FAQ

How hard is the Benchling protein chain problem really?+

Medium at most. It's DFS over a small DAG with at most 15 nodes. The logic is short. Most lost points come from output formatting and sort order, not the algorithm. If you've written path enumeration before, it's quick.

What's the core trick?+

Group sequences by start value, then DFS from every sequence. At each node, emit the chain so far, then extend with any sequence whose start equals the current end. Since intervals strictly advance, there are no cycles, so no visited set is needed.

How should I sort the results?+

Build each full string as joined_names:start:end, collect them all, then sort the strings with standard ASCII comparison. Don't sort by name lists or by numeric start. The example output shows plain lexicographic order on the complete string.

Do I need to implement the new-sequence follow-up?+

No. The judged function only does the initial enumeration. Be ready to talk about it though. Keep start and end indexes, and only enumerate chains that include at least one new sequence, deduplicating chains that contain several new ones.

How do I prepare for this in 48 hours?+

Write DFS path enumeration on a DAG twice from scratch. Practice joining names with underscores and formatting strings with numbers. Test with an empty name and a single-element input. Then check your sort against the example output by hand.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Benchling.

OA at Benchling?
Invisible during screen share
Get it