Similar DNA Under Rotation and Substitution
Reported by candidates from Benchling's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure this Benchling problem hinges on is just the string itself, doubled. Reported in September 2020, it asks you to count candidate DNA strings that have some circular rotation within Hamming distance 3 of a reference. It looks like a string-matching puzzle, but it's really a brute-force check with a neat indexing trick. Lengths cap at 200 and candidates at 1000, so the simple approach fits. If you blank on the rotation handling during the live OA, StealthCoder runs invisibly on your desktop as a safety net and gives you the solution while you stay in control.
The problem
Given a reference DNA string and candidate DNA strings, count how many candidates have some circular rotation whose Hamming distance from the reference is at most three. Only substitutions are allowed; insertion and deletion are not allowed. Function countSimilarDNA(reference: String, candidates: String[]) → int Examples Example 1 reference = "AAAAG" candidates = ["AAAGA","CCCCC","AAAAT"] return = 2 AAAGA matches after rotation, AAAAT needs one substitution, and CCCCC needs more than three. Constraints 1 <= reference.length <= 200. 1 <= candidates.length <= 1000. Every string contains only A, C, G, and T.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: for each candidate, try every rotation offset from 0 to n-1 and count mismatches against the reference. Don't build rotated strings. Index with (i + shift) % n, or concatenate the candidate with itself and compare a window of length n. Break out early once mismatches exceed 3, and stop checking that candidate as soon as one rotation passes. Cost is roughly candidates x n x n, about 40 million character comparisons at the max, which is fine. Common pitfalls: skipping the length check (a candidate of a different length can't match, so skip it), counting a candidate twice because multiple rotations pass, and treating this as edit distance. Only substitutions count, so no DP is needed. If the early-exit logic or modulo indexing trips you up mid-assessment, StealthCoder can hand you a clean version fast.
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 Similar DNA Under Rotation and Substitution 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 Benchling's OA.
Benchling 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.
Similar DNA Under Rotation and Substitution FAQ
What's the trick in the Benchling DNA rotation problem?+
Try every rotation of each candidate against the reference and count position-wise mismatches. If any rotation has 3 or fewer mismatches, the candidate counts once. Use modulo indexing or a doubled string so you never actually build rotated copies.
Do I need dynamic programming or edit distance?+
No. The problem says only substitutions are allowed, so it's plain Hamming distance between equal-length strings. Edit distance would be overkill and would give wrong answers, since insertions and deletions aren't permitted.
Will brute force pass the constraints?+
Yes. With reference length up to 200 and up to 1000 candidates, you do about 1000 x 200 x 200 comparisons in the worst case. Add an early break when mismatches pass 3 and it runs comfortably.
What edge cases should I test?+
Candidates with a different length than the reference, a reference of length 1, candidates identical to the reference, and strings where several rotations qualify. The last one checks that you count each candidate only once.
How do I prepare for this in 48 hours?+
Practice circular-string indexing with the modulo operator and writing a Hamming distance loop with early exit. Write this exact problem once from scratch, then test it against the example where AAAGA, AAAAT and CCCCC give 2.