Loading
Loading
A jeweller has a strand of lettered beads and wants to remove some of them so that what remains reads the same from either end. She may remove any beads, but cannot reorder the ones she keeps.
Return the largest number of beads she can keep. Unlike finding a mirrored stretch of adjacent beads, the kept beads here need not be next to each other on the original strand.
beads = "character"ends c … c (positions 0 and 5)keep both: +2inside: h a r aa … a match: +2inside: ra single bead: +1kept: c a r a clength 55Sign 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(n²) 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.
Keep c, a, r, a, c.
Example 2
All beads differ, so only one can be kept.