#C14867. Maximum Distinct Characters in Substring

    ID: 44563 Type: Default 1000ms 256MiB

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" and k = 3, the answer is 3.
  • For s = "aaaa" and k = 2, the answer is 1.

inputFormat

The input will be provided via standard input (stdin) and consists of two lines:

  1. The first line contains the string s.
  2. 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.

## sample
abcabcbb
3
3