DNA Sequence Match
Updated
Problem statement
DNA Sequence Match
A text file is represented by lines, where every line is a DNA string. Find every exact occurrence of target in the file.
Return the matches in line order and then start-index order. Encode each match as lineIndex:startIndex, using zero-based indices. Overlapping matches count separately. Return an empty array when no match exists.
Function
findDnaSequenceMatches(lines: String[], target: String) → String[]Examples
Example 1
lines = ["AACGTA","CGTA"]target = "CGT"return = ["0:2","1:0"]CGT begins at index 2 in the first line and index 0 in the second line.
Example 2
lines = ["AAAAA"]target = "AAA"return = ["0:0","0:1","0:2"]The three occurrences overlap, and all of them are returned.
Example 3
lines = ["ACGT"]target = "TT"return = []The target does not occur in the file.
Constraints
1 ≤ lines.length ≤ 10,0000 ≤ lines[i].lengthand the sum of all line lengths is at most200,000.1 ≤ target.length ≤ 100,000- Every line and
targetcontains onlyA,C,G, andT.
More SpaceX interview questions
- Starlink Beam PlannerOA · PHONE SCREEN · Seen Nov 2026
- Timestamped Telemetry Stream DifferencesPHONE SCREEN · Seen Sep 2026
- Number of IslandsPHONE SCREEN · Seen Aug 2026
- Number of Islands IIPHONE SCREEN · Seen Aug 2026
- Button Combination DetectorPHONE SCREEN · Seen Feb 2026
- Rocket Component CostONSITE INTERVIEW · Seen Aug 2025
- Pressure Chamber Linear InterpolationPHONE SCREEN · Seen Jun 2025
- Speed to Pressure LookupPHONE SCREEN · Seen Mar 2025
- Simplified Time-Based Key-Value StorePHONE SCREEN · Seen Nov 2023
- Find the Duplicate NumberONSITE INTERVIEW · Seen Jan 2021
Similar questions at other companies
- Parse Router LogsIntuit · OAIntuit interview questions
- Simplify a Quadratic ExpressionOpenAI · OAOpenAI interview questions
- Correct Apartment Bedroom CountsRamp · OARamp interview questions
- Remove CSS Comments and Find Hex ColorsAdobe · OAAdobe interview questions
- Create New VersionCisco · OACisco interview questions
- Order LayoutAmazon · OA
- Validate and Parse HTTP RequestsIBM · OAIBM interview questions
- Convert Backticked Identifiers to Camel CaseZipRecruiter · OAZipRecruiter interview questions
- Simplified XML ValidatorAirbnb · OAAirbnb interview questions
- Hidden ArtifactsIMC Trading · OAIMC Trading interview questions