#K35727. Shortest Word in a String

    ID: 25596 Type: Default 1000ms 256MiB

Shortest Word in a String

Shortest Word in a String

Given a string s that contains a sequence of words separated by spaces, your task is to determine the length of the shortest word in the string. If the string is empty or consists only of whitespace characters, output -1.

Note: A word is defined as a contiguous sequence of non-space characters. Use the \s regular expression to split the string when needed.

For example, for the string The quick brown fox jumps over the lazy dog, the shortest word is fox with a length of 3.

Mathematically, if we denote the set of words as \(\{w_1, w_2, \dots, w_n\}\), then you are to compute \(\min_{1 \le i \le n}\{|w_i|\}\). If the string is empty (or contains no words), the result is defined as -1.

inputFormat

The input consists of a single line of text representing the string s. The string may contain multiple spaces between words. Read the input from standard input (stdin).

outputFormat

Output a single integer which is the length of the shortest word in the input string. If the input string is empty or has no valid words, output -1. The output should be written to standard output (stdout).

## sample
The quick brown fox jumps over the lazy dog
3