JJOOII
InterviewTime limit1sMemory limit128 MB
Find the largest k such that k J's, then k O's, then k I's appear consecutively in the given string.
- Level
Medium5 of 10
- Topics
- String, Prefix sum, Binary search
- Solved
- No attempts yet
Problem
We work with strings made up of only the three characters J, O, and I.
A string is a substring of a string if can be formed by adding zero or more characters to both the front and the back of ; that is, must appear contiguously inside . For example, JJOOII is a substring of OJJOOIIOJOI, whereas JOI is not a substring of JOOI.
For a non-negative integer , a level- JOI sequence is the string consisting of copies of J, then copies of O, then copies of I, in that order. For example, JJOOII is a level- JOI sequence.
You are given a string of length over the characters J, O, and I. Find the largest such that a level- JOI sequence is a substring of .
Input
The first line contains the string , made up of the characters J, O, and I.
Output
Print, on a single line, the largest such that a level- JOI sequence is a substring of . (If no level--or-higher JOI sequence is a substring, print 0.)
Constraints
- , where is the length of .