#C7853. Substring with Most Distinct Characters

    ID: 51770 Type: Default 1000ms 256MiB

Substring with Most Distinct Characters

Substring with Most Distinct Characters

Given a string (S) and an integer (K), your task is to find a contiguous substring of length (K) that contains the maximum number of distinct characters. In other words, for each substring (S[i:i+K]), compute (d(S[i:i+K]) = \lvert { c : c \in S[i:i+K] } \rvert) and return the substring with the maximum (d(S[i:i+K])). If there are multiple substrings with the same maximum value, return the one that appears first.

inputFormat

The input is read from standard input (stdin). The first line contains a single integer (T), representing the number of test cases. Each of the following (T) lines contains a string (S) and an integer (K) separated by a space.

outputFormat

For each test case, print one line to standard output (stdout) containing the substring of length (K) with the maximum number of distinct characters. If there are multiple valid answers, output the one that occurs first in (S).## sample

2
abcde 3
abacabad 3
abc

bac

</p>