#K13771. Smallest Character in Substring
Smallest Character in Substring
Smallest Character in Substring
You are given a string s
of length n
consisting of lowercase English letters. You are also given q
queries. Each query consists of two integers l
and r
, representing the start and end indices of a substring (1-indexed). For each query, your task is to determine the lexicographically smallest character in the corresponding substring.
The lexicographical order is the same as the dictionary order. More formally, for a substring sl,r, you must find the character c such that
where the indices are 1-indexed.
Example:
Input: 5 abcde 2 2 4 1 5</p>Output:
b a
Note that each query's answer should be output on a separate line.
inputFormat
The input is given via standard input and follows the format below:
n s q l1 r1 l2 r2 ... lq rq
Where:
n
is the length of the strings
.s
is a string of lowercase English letters.q
is the number of queries.- Each of the next
q
lines contains two space-separated integersl
andr
indicating the starting and ending indices of a substring.
outputFormat
For each query, print the lexicographically smallest character in the substring on a separate line. The output is produced via standard output.
## sample5
abcde
2
2 4
1 5
b
a
</p>