Loading
Loading
A sequence of DNA bases sometimes contains a mirrored core — a stretch that reads the same forwards and backwards.
Return the longest mirrored stretch in the input. If several are tied for longest, return the one that starts earliest.
bases = "ACGTGCA"centre at index 3 (T)expand: G…G matchesexpand againC…C matchesexpand againA…A matches — whole string"ACGTGCA"Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n²) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
The whole string is mirrored.
Example 2
An even-length core.
Example 3
No stretch longer than one character is mirrored, so the earliest single character wins.