#K8281. Longest Substring Queries
Longest Substring Queries
Longest Substring Queries
You are given a string s
consisting of lowercase Latin letters and a series of queries. Each query consists of a single character. For each query, you need to determine the length of the longest contiguous substring within s
that contains only the queried character.
A contiguous substring is defined as a sequence of consecutive characters in the string. Formally, if we denote a contiguous substring as \(S_i\), you are required to compute
[
L = \max_{i} { \text{length}(S_i) }
]
where each \(S_i\) is a maximal substring comprised solely of the queried character. If the character does not appear in s
, the answer for that query is 0.
This problem tests your ability to scan a string efficiently and process multiple queries.
inputFormat
The input is given via standard input (stdin) in the following format:
- A line containing the string
s
, which consists of only lowercase Latin letters. - A line containing an integer
n
, denoting the number of queries. n
lines follow, each containing a single lowercase letter representing a query.
outputFormat
For each query, output a single integer on a new line that represents the length of the longest contiguous segment in s
consisting solely of the queried character.
abaaaabbcc
4
a
b
c
d
4
2
2
0
</p>