#K5576. Find Unique Substrings
Find Unique Substrings
Find Unique Substrings
You are given a string s
and an integer k
. Your task is to find all unique substrings of s
that have a length exactly equal to k
and print them in lexicographical (i.e., \(\text{lexicographical}\)) order.
Note that if k
is less than or equal to 0 or greater than the length of s
, then the output should be empty.
Example:
- Input: s = "abcabc", k = 3
- Output: abc bca cab
The output substrings should be separated by a space.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the string
s
. - The second line contains the integer
k
.
outputFormat
Print the unique substrings of length k
from s
in lexicographical order. The substrings should be separated by a space. If there are no valid substrings, print nothing.
abcabc
3
abc bca cab