Karel is a frustrated painter who works by day in an electrical repair
shop. Inspired by the color-coded bands on resistors, he is painting
a series of long, narrow canvases with bold colored stripes. However,
Karel is lazy and wants to minimize the number of brush strokes it takes
to paint each canvas.
Abbreviating each color to a single uppercase letter, Karel would
write the stripe pattern red-green-blue-green-red as "RGBGR"
(quotes added for clarity). It would take him three brush strokes to
paint this pattern.
The first stroke would cover the entire canvas in red (RRRRR).
The second stroke would leave a band of red on either side and fill
in the rest with green (RGGGR).
The final brush stroke would fill in the blue stripe in the center
(RGBGR).
Given a stripe pattern stripes as a String, calculate the minimum number of
brush strokes required to paint that pattern.
|