#C8986. Smallest Window Containing All Unique Characters

    ID: 53028 Type: Default 1000ms 256MiB

Smallest Window Containing All Unique Characters

Smallest Window Containing All Unique Characters

Given a string S, your task is to find the length of the smallest substring (window) that contains every distinct character present in S at least once.

Let \(U\) be the set of all characters in S. You need to determine the minimum length \(L\) such that there exists a contiguous substring of length \(L\) which contains every character from \(U\) at least once.

If the input string is empty, output inf (which represents \(\infty\)).

Examples:

  • Input: "aabcbcdbca" → Output: 4
  • Input: "aaab" → Output: 2
  • Input: "aaa" → Output: 1
  • Input: "abcd" → Output: 4
  • Input: "abcdef" → Output: 6
  • Input: "" → Output: inf

inputFormat

The input consists of a single line containing the string S.

Note: The string can be empty.

outputFormat

Output a single integer denoting the length of the smallest substring of S containing all distinct characters. If S is empty, output inf.

## sample
aabcbcdbca
4