IOIOI
InterviewTime limit1sMemory limit256 MB
Count the occurrences of the alternating string P_N (N+1 I's and N O's) as a substring of S, counting overlaps.
- Level
Medium5 of 10
- Topics
- String, Sliding window, Implementation, String matching
- Solved
- No attempts yet
Problem
Let be the string formed from copies of I and copies of O in which I and O alternate. That is, starts and ends with I, with Os in between.
- =
IOI - =
IOIOI - =
IOIOIOI - =
IOIOI…OI(withOs)
Given a string consisting only of I and O and an integer , write a program that counts how many times occurs in . Overlapping occurrences are counted separately.
Input
The first line contains the integer .
The second line contains , the length of the string .
The third line contains the string .
Output
Print, on a single line, how many times occurs in .
Constraints
- consists only of
IandO.