#K13771. Smallest Character in Substring

    ID: 23987 Type: Default 1000ms 256MiB

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

c=minlirs[i]c = \min_{l \le i \le r}{s[i]}

where the indices are 1-indexed.

Example:

Input:
5
abcde
2
2 4
1 5

Output:

b a

</p>

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 string s.
  • s is a string of lowercase English letters.
  • q is the number of queries.
  • Each of the next q lines contains two space-separated integers l and r 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.

## sample
5
abcde
2
2 4
1 5
b

a

</p>