Unique DNA Sequences Under Circular Rotation
Reported by candidates from Benchling's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
This Benchling OA, reported in September 2020, looks like a DNA problem but it's really a canonical-form problem. Every string has a rotation class, and you're counting classes. Pick one representative per class, drop them in a set, return the set size. That's the whole question. If the biology framing rattles you, ignore it, it's decoration. And if you blank on how to pick the representative, StealthCoder sits invisibly on your screen during the live OA and hands you the approach so you're not stuck staring at the prompt.
The problem
Given DNA strings made of A, C, G, and T, count the distinct sequences when two strings are considered equal if one is a circular rotation of the other. Function countUniqueRotations(sequences: String[]) → int Examples Example 1 sequences = ["TGAAA","ATGAA","AATGA"] return = 1 All three strings belong to one rotation class. Example 2 sequences = ["AAA","TAA","TAT","ATA"] return = 3 TAA, AAT, and ATA are rotations; AAA and TAT each form another class. Constraints 1 <= sequences.length <= 1000. All strings are non-empty, have the same length, and contain only A, C, G, and T. Each string length is at most 200.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is normalizing each string to a canonical rotation. Simplest: for each string s, build all n rotations and take the lexicographically smallest. Add that to a hash set. With 1000 strings of length at most 200, that's 1000 * 200 * 200 = 40 million character operations, which is fine. A cleaner shortcut: the smallest rotation of s is found inside s+s, so slice substrings of length n from s+s and take the min. The common pitfall is comparing strings pairwise, which is slow and messy. Another is forgetting that the strings all share one length, so you don't need to handle mismatched lengths. Booth's algorithm or minimal rotation in linear time is overkill here. Check example 2: TAA, ATA, AAT all normalize to AAT, while AAA and TAT stay separate, giving 3. If you freeze mid-OA, StealthCoder is the hedge that gives you the canonical-form solution in real time.
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 Unique DNA Sequences Under Circular Rotation 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.
Unique DNA Sequences Under Circular Rotation FAQ
What's the trick for the Benchling unique DNA sequences problem?+
Canonicalize each string to its smallest rotation, then count distinct canonical forms with a set. Two strings are rotations of each other exactly when their smallest rotations match. No pairwise comparison needed, which keeps the code short and the logic easy to defend.
How hard is this OA really?+
Easy to medium. The idea is one insight: reduce each equivalence class to one representative. Once you see that, the code is about ten lines. The difficulty is recognizing it under pressure, not implementing it.
Is brute-force rotation generation fast enough?+
Yes. Max 1000 strings, each length 200 at most. Generating 200 rotations of 200 characters per string is roughly 40 million character operations total. That's fine. You don't need a linear-time minimal rotation algorithm unless you want to show off.
How do I generate rotations cleanly?+
Concatenate the string with itself, then take every substring of length n starting at index 0 through n-1. Each one is a rotation. Take the min of those. In most languages that's a one-liner with a loop or comprehension.
How should I prep for this in 48 hours?+
Practice the canonical-form idea: normalize, put in a set, count. Then do a few string rotation problems like checking if one string is a rotation of another using s+s. Also test edge cases: length 1 strings, all identical characters, and a single input string.