#C14867. Maximum Distinct Characters in Substring
Maximum Distinct Characters in Substring
Maximum Distinct Characters in Substring
You are given a string s and an integer k. Your task is to determine the maximum number of distinct characters in any contiguous substring of s that has a length of k.
Formally, if we denote a substring of s starting at index i (0-indexed) with length k as \( s[i..i+k-1] \), you need to compute:
[ \max_{0 \leq i \leq n-k} \left| { s[i], s[i+1], \dots, s[i+k-1] } \right|, ]
where \(n\) is the length of s. It is guaranteed that k is at most the length of the string.
Example:
- For
s = "abcabcbb"
andk = 3
, the answer is3
. - For
s = "aaaa"
andk = 2
, the answer is1
.
inputFormat
The input will be provided via standard input (stdin) and consists of two lines:
- The first line contains the string s.
- The second line contains the integer k.
You may assume that 1 ≤ k ≤ |s|, where |s| denotes the length of the string.
outputFormat
Output a single integer to standard output (stdout), representing the maximum number of distinct characters in any substring of s of length k.
## sampleabcabcbb
3
3