SKK String
Time limit1sMemory limit1024 MB
Find the longest substring where the count of K equals twice the count of S, with both letters present, or report -1.
- Level
Medium6 of 10
- Topics
- Prefix sum, Hash map, String, Array
- Solved
- No attempts yet
Problem
A string is called an SKK string if the number of K's it contains is exactly times the number of S's, and both S and K appear at least once.
An SKK string may contain letters other than S and K.
Given a string consisting only of uppercase letters, write a program that finds the longest SKK string among the substrings of .
Input
The first line gives a string consisting only of uppercase letters, with length between and .
Output
Print the length of the longest SKK string among the substrings of . If no such string exists, print -1.
Hint
A new string formed by selecting consecutive characters from a string is called a substring of .
For example, "appl", "ap", and "ple" are substrings of "apple", while "ppe" and "apl" are not substrings of "apple".