#K12231. Smallest Distinct Characters in Covered Substrings

    ID: 23645 Type: Default 1000ms 256MiB

Smallest Distinct Characters in Covered Substrings

Smallest Distinct Characters in Covered Substrings

Given a string s, find the smallest number of distinct characters in any non-empty substring of s that together covers all characters present in s. In other words, consider all non-empty substrings of s that contain every distinct character from s; the answer is the minimum possible count of distinct characters in such a substring. Note that if s is empty, the answer is defined to be 0.

Since any substring that covers all distinct characters of s must contain at least all these distinct characters, the answer will simply be the total number of unique characters in s (or 0 for an empty string).

Examples:

  • For s = "abcde", the output is 5.
  • For s = "abac", the output is 3.
  • For s = "a", the output is 1.
  • For s = "aaaa", the output is 1.
  • For s = "abcabcabc", the output is 3.
  • For s = "abababab", the output is 2.
  • For an empty string, the output is 0.

inputFormat

The input is provided via standard input (stdin) and consists of a single line containing the string s. The string may be empty.

outputFormat

Output the smallest number of distinct characters in any non-empty substring of s that covers every character from s. If s is empty, output 0. The output should be printed to standard output (stdout).

## sample
abcde
5