Degenerate DNA Substring Search
Updated
Problem statement
Search the uploaded DNA sequences for a substring matching query. Sequence characters are standard bases A, C, G, and T. Query characters may also use IUPAC degenerate bases:
R=AG,Y=CT,M=AC,K=GT,W=AT,S=CGB=CGT,D=AGT,H=ACT,V=ACG,N=ACGT
Return the distinct matching sequences in lexicographic order.
Indexed search follow-up
Index each uploaded sequence by its four-base substrings. For a query of at least four bases, form candidate sets for its four-grams and intersect them, then verify each candidate by exact substring matching. For example, ATTAGATT with query GATTA is a false positive for intersection alone: the required four-grams occur in different positions. For degenerate bases, union all compatible concrete four-gram postings before intersection; verify the original degenerate query against every remaining sequence. Queries shorter than four bases need a direct-scan fallback. Discuss retaining the index for multiple queries. Your function only searches the array it is given.
Function
findDegenerateDnaMatches(sequences: String[], query: String) → String[]Examples
Example 1
sequences = ["GATTACA","GATTG"]query = "GATT"return = ["GATTACA","GATTG"]Both sequences contain GATT.
Example 2
sequences = ["GATTACA","GATTG"]query = "GATTM"return = ["GATTACA"]M accepts A or C, so only GATTACA matches.
Constraints
1 <= sequences.length <= 1000.1 <= query.length <= 100.1 <= sequences[i].length <= 1000.- Sequence characters are
ACGT; query characters are valid standard or degenerate IUPAC bases.
More Benchling interview questions
- Validate Nested JSON Against a SchemaONSITE INTERVIEW · Seen Dec 2025
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Jul 2021
- Bounded HTTP Retry FlowPHONE SCREEN · Seen Nov 2025
- Future-Aware Cache EvictionPHONE SCREEN · Seen Aug 2025
- Generate All Contiguous Protein ChainsPHONE SCREEN · Seen Jul 2024
- 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
- 2048 Move SimulatorOA · Seen Feb 2019
Similar questions at other companies
- Longest Substring Without Repeating CharactersOracle · ONSITE INTERVIEWOracle interview questions
- Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Longest Substring Without Repeating CharactersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Substring Without Repeating CharactersGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Substring Without Repeating CharactersAmazon · ONSITE INTERVIEW
- Longest Substring Without Repeating CharactersInfosys · ONSITE INTERVIEWInfosys interview questions
- Longest Substring Without Repeating CharactersOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Longest Substring Without Repeating CharactersBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Longest Substring with At Most K Distinct CharactersGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Substring Without Repeating CharactersBank of America · ONSITE INTERVIEWBank of America interview questions