#C10794. Unique Substrings Extraction
Unique Substrings Extraction
Unique Substrings Extraction
Given a string \(S\) and a positive integer \(L\), your task is to extract all unique substrings of \(S\) that have exactly \(L\) characters. A substring is defined as a contiguous sequence of characters in \(S\). If \(L \le 0\) or \(L > |S|\) (where \(|S|\) denotes the length of \(S\)), then no valid substring exists and you should output an empty result.
The output should list all unique substrings in lexicographical order, separated by a single space. If there are no valid substrings, output an empty line.
Examples:
- For \(S = 'abcdef'\) and \(L = 2\), the unique substrings are: ab, bc, cd, de, ef.
- For \(S = 'abc'\) and \(L = 4\), the output is empty since \(L > |S|\).
- For \(S = 'aaa'\) and \(L = 1\), the only unique substring is: a.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the string \(S\) (non-empty or empty).
- The second line contains an integer \(L\), which is the length of substrings to extract.
outputFormat
Output to standard output (stdout) a single line with all unique substrings of length \(L\) found in \(S\), sorted in lexicographical order and separated by a single space. If no valid substrings exist, output an empty line.
## sampleabcdef
2
ab bc cd de ef