#C10513. Minimum Flips to Prevent Adjacent Heads
Minimum Flips to Prevent Adjacent Heads
Minimum Flips to Prevent Adjacent Heads
You are given a sequence of coins, where each coin is marked either H
(Heads) or T
(Tails). Your task is to determine the minimum number of coin flips required so that no two adjacent coins show heads (H
).
In a single flip, you can change a coin from H
to T
. It is always optimal to flip the coin at the second position of any consecutive pair of heads in order to prevent further conflicts.
The input is read from standard input (stdin) and the result must be printed to standard output (stdout).
inputFormat
The first line contains an integer n denoting the number of coins. The second line contains a string of length n comprised solely of the characters H
and T
, representing the current state of each coin.
outputFormat
Output a single integer representing the minimum number of flips required so that no two adjacent coins are heads.
## sample5
TTTHT
0