#K85492. Smallest Lexicographical Substring
Smallest Lexicographical Substring
Smallest Lexicographical Substring
Given an integer k and a string s, your task is to find the lexicographically smallest substring of length k from s.
You need to consider every contiguous substring of length k in s and determine the one which comes first in lexicographical order. In other words, if we denote a substring by t, find the smallest t such that for any other valid substring u of length k, t < u holds true in lexicographical (dictionary) order.
Note: Lexicographical order is similar to dictionary order, where strings are compared character by character.
The required function, when implemented, will receive the input from the standard input (stdin) and should output the result to the standard output (stdout).
Mathematically, if we define a substring of s of length k as:
\( s[i:i+k] \) for \( 0 \leq i \leq |s| - k \),
you are required to find the minimum \( s[i:i+k] \) in lexicographical order.
inputFormat
The input consists of two lines:
- The first line contains an integer k representing the length of the substring to be found.
- The second line contains the string s.
You can assume that k is a positive integer and that s has a length at least k.
outputFormat
Output the smallest lexicographical substring of length k from the given string s on a single line.
## sample3
abracadabra
abr