#K63077. Distinct Substrings in Lexicographical Order
Distinct Substrings in Lexicographical Order
Distinct Substrings in Lexicographical Order
You are given a string s and an integer n. Your task is to extract all distinct contiguous substrings of length n from s and then output them in lexicographical order.
If n
is greater than the length of s
, output None
. Otherwise, list all unique substrings of length n
, sorted in lexicographical (dictionary) order. The output should be a single line containing the substrings separated by a single space.
Note: A substring is a contiguous sequence of characters within a string.
inputFormat
The input consists of two lines. The first line contains the string s
(which does not contain spaces). The second line contains a positive integer n
.
outputFormat
Output a single line with all distinct substrings of length n
from s
in lexicographical order separated by a space. If no substring of length n
can be formed (i.e. if n
is greater than the length of s
), output None
.
abcdef
3
abc bcd cde def