#K3896. Shortest Substring Containing a Character

    ID: 26314 Type: Default 1000ms 256MiB

Shortest Substring Containing a Character

Shortest Substring Containing a Character

You are given a string s and a character c. Your task is to find the length of the shortest substring of s which contains c at least once. A substring is a contiguous sequence of characters. Notice that the trivial case always exists: if c occurs in s, then the single character c by itself forms a valid substring with length 1. If c is not present in s, output -1.

For example, if s = "hello" and c = 'e', then the shortest substring containing 'e' is "e" and the answer is 1.

inputFormat

The first line of input contains a single integer T denoting the number of test cases. Each of the following T lines contains a test case with two inputs: a string s and a character c separated by a space.

outputFormat

For each test case, output a single integer — the length of the shortest substring of s that contains the character c. If c does not appear in s, output -1. Each answer should be printed on a new line.

## sample
4
hello e
abc a
xyz x
abcdef z
1

1 1 -1

</p>