Loading
Loading
A sign maker cuts a strip of letters into pieces. Every piece must read the same forwards and backwards — a palindrome — so it can be mounted on a glass door and read from either side.
Return how many different ways the string s can be cut so that every piece is a palindrome. Two ways differ if they cut at different positions. Not cutting at all counts as one way when the whole string is a palindrome.
s = "noon"n | o | o | nsingle letters are always palindromesn | oo | nthe middle pair mirrorsnoonthe whole strip mirrors3Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
a|a|b and aa|b.
Example 2
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.
n|o|o|n, n|oo|n and noon.