We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. HourRank 7
  3. Paint The Tiles

Paint The Tiles

Problem
Submissions
Leaderboard
Discussions
Editorial

Nikita has a line of tiles indexed from to . She wants to paint them to match a color configuration, , which is comprised of colors: and .

In one stroke, Nikita can paint or more adjacent tiles a single color. After she finishes painting, each tile should be painted color .

It should be noted that it is not allowed to apply more than stroke on a tile.

Given the required color configuration, find and print the minimum number of strokes required for Nikita to paint all tiles.

Note: In a line of tiles, tiles with the indices and are considered adjacent only if .

Input Format

The first line contains a single integer, , denoting the number of tiles to be painted.
The second line contains a string, , denoting the desired color configuration.

For each character in :

  • If , it means the tile must be painted red.
  • If , it means the tile must be painted blue.

Constraints

Output Format

Print the minimum number of strokes required to paint all tiles in the desired color configuration.

Sample Input 0

5  
RRRRR

Sample Output 0

1

Sample Input 1

5  
RRBRR

Sample Output 1

3

Sample Input 2

5  
BRBRB

Sample Output 2

5

Explanation

Sample Case 0:

Nikita will paint all consecutive tiles red in a single stroke:

Sample Case 1:

Nikita will need strokes to paint all tiles:

Author

ma5termind

Difficulty

Easy

Max Score

25

Submitted By

1038

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download all test cases
Suggest Edits
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature