Shil and Greedy approach
Practice
4.4 (5 votes)
Algorithms
Approved
Breadth first search
Graphs
Medium
Open
Problem
86% Success 1279 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Shil is very bad at greedy algorithms. So he decided to practice a lot of greedy problems. He came across a very good problem.Problem is as follows:
Given a linear strip of length N. Strip consists of N cells painted in either BLACK or WHITE color. At each move you can do following process:

  1. Take any 2 or 3 contiguous cells.
  2. Invert their colors (i.e replace BLACK cells with WHITE cells and WHITE cells with BLACK cells).

You are required to answer minimum number of moves in which you can change all the cells into same color( either WHITE or BLACK).

Input
First line of input contains N which represents length of strip.
Second line of input consists of string of length N. Each character of string will be W or B . B represents Black cell and W represents White cell.

Output
Minimum number of moves in which you can change all the cells into same color .i.e make the whole strip consisting of cells having same color.

Constraints
2 ≤ N ≤ 20

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
24 votes
Tags:
AlgorithmsGraphsMediumShortest Path Algorithm
Points:30
20 votes
Tags:
AlgorithmsDijkstra's algorithmGraphsMediumShortest Path Algorithm
Points:30
4 votes
Tags:
GraphsShortest Path AlgorithmsAlgorithms