#C2247. Maximum Distinct Characters in a Substring
Maximum Distinct Characters in a Substring
Maximum Distinct Characters in a Substring
Given a string \(s\) and an integer \(k\), find the maximum number of distinct characters in any substring of \(s\) with length \(k\). If no such substring exists (i.e., when \(k > |s|\)), output \(-1\).
For example, consider \(s = \texttt{abcba}\) and \(k = 3\). The possible substrings of length 3 are \(\texttt{abc}\), \(\texttt{bcb}\), and \(\texttt{cba}\). Their distinct character counts are 3, 2, and 3 respectively, so the answer is 3.
inputFormat
The input is given from standard input (stdin) and consists of two lines. The first line contains the string (s). The second line contains the integer (k).
outputFormat
Output to standard output (stdout) a single integer representing the maximum number of distinct characters found in any substring of (s) with length (k). If no such substring exists, output (-1).## sample
abcba
2
2