#C4148. Unique Substrings Finder
Unique Substrings Finder
Unique Substrings Finder
You are given a string s and an integer k. Your task is to find all unique substrings of s that have length k and print them in lexicographical order.
In other words, you need to extract all substrings substring such that:
$$\text{substring} = s[i\ldots i+k-1], \quad 0 \leq i \leq |s|-k$$
and then output the unique ones in sorted order. If no valid substring exists (i.e. when \(k > |s|\)), print an empty line.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains the string
s
. - The second line contains the integer
k
.
It is guaranteed that s
does not contain newline characters.
outputFormat
Print the unique substrings of length k
found in the string s
in lexicographical order, separated by a space. If there are no valid substrings, output an empty line.
abcde
3
abc bcd cde