Loading
Loading
A parade is described by a string of lowercase letters, one per float; the letter is the club that owns the float. The marshals want to cut the parade into as many consecutive sections as possible, with one rule: all floats of the same club must end up in the same section.
Return the lengths of the sections, from front to back.
parade = "abacdcdeff"a last seen at 2section must run to at least index 2aba | ...b's last is 1, nothing extends — cut after index 2cdcdc last at 5, d last at 6 — cut after 6ee appears once — cutffsizes 3, 4, 1, 2[3, 4, 1, 2]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.
Sections: aba | cdcd | e | ff.
Example 2
Sections: zyzy | x.