SDE Path

Longest Substring with At Most K Distinct Characters

Medium

Longest Substring with At Most K Distinct Characters

Find the length of the longest substring containing at most K distinct characters.

Input format

The first line contains a string S. The second line contains K.

Output format

Print the length of the longest substring with at most K distinct characters.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
eceba 2
Expected output
3
Example 2
Input
aa 1
Expected output
2