Generate All Contiguous Protein Chains
Updated
Problem statement
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. Your function only does the first full listing.
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 sequence counts as a chain by itself. A longer chain forms when the next sequence starts exactly where the current one ends, and the names are joined with an underscore.
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. - Every sequence name contains only ASCII characters, and an empty name is allowed. Lexicographic order compares those characters.
More Benchling interview questions
- Bounded HTTP Retry FlowPHONE SCREEN · Seen Nov 2025
- Future-Aware Cache EvictionPHONE SCREEN · Seen Aug 2025
- Eight-Direction Keyboard Typing TimePHONE SCREEN · Seen Apr 2022
- Generate Proteins from Contiguous Named SequencesPHONE SCREEN · Seen Aug 2021
- Next Palindrome NumberPHONE SCREEN · Seen Jul 2021
- Apply Overlapping HTML Formatting RangesPHONE SCREEN · Seen Feb 2019
- Validate Nested JSON Against a SchemaONSITE INTERVIEW · Seen Dec 2025
- Degenerate DNA Substring SearchONSITE INTERVIEW · Seen Jun 2024
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Jul 2021
- 2048 Move SimulatorOA · Seen Feb 2019
Similar questions at other companies
- Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
- Validate and Resolve Evaluation ChainsPlaid · PHONE SCREEN · ONSITE INTERVIEWPlaid interview questions
- Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
- Root of the Largest TreeGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Find the Unique User with Access to Every CameraVerkada · PHONE SCREENVerkada interview questions