#K57327. Magician's Swap Puzzle
Magician's Swap Puzzle
Magician's Swap Puzzle
In this problem, you are given an integer (N) and a string of instructions of length (N). Each instruction is either 'L' or 'R'. The Warrior can only follow a safe path, but whenever the instructions contain a dangerous pattern in the form of 'RL' consecutively, the Magician must perform a swap to neutralize the threat. Your task is to determine the minimum number of swaps required so that the Warrior will never be faced with a dangerous 'RL' segment during his journey. Mathematically, you need to count the number of indices (i \ (0 \le i < N-1)) such that (s[i] = R) and (s[i+1] = L).
inputFormat
The input consists of two lines. The first line contains an integer (N) representing the length of the instruction string. The second line contains the instruction string, which is a sequence of exactly (N) characters, each being either 'L' or 'R'.
outputFormat
Output a single integer on a new line, which represents the minimum number of swaps required to remove all dangerous 'RL' segments from the instruction string.## sample
7
LRLLRRL
2
</p>