Lexicographically Least Substring

View as PDF

Submit solution


Points:5
Time limit:2.0s
Memory limit:64M

Problem types

Brute Force Practice 2

You have a string (indexed from 0) with no more than 50 lowercase characters. Find the lexicographically least substring with a length of at least K. A string S is said to be lexicographically smaller than a string T if |S| < |T| and S is a prefix of T or S_k < T_k and S_i = T_i (0 \le i < k, 0 \le k < min(|S|, |T|)). Here, |X| denotes the length of the string.

Input

The first line will have the string.

The second line will have K.

Output

Print the lexicographically least substring of length at least K.

Sample Input

iloveprogramming
4

Sample Output

ammi

Comments


  • -7
    onlyIfStatement
     commented on Oct. 31, 2016 edited
    Incorrect?

    NVM


    • 3
      Kirito
       commented on Nov. 1, 2016 edit 2

      Are you implying that all the people who have AC got it by accident? Your program is wrong, try the following input.

      baaazzz
      4
      

  • 0
    bobhob314
     commented on Dec. 25, 2014
    (: ^ o )

    Python hax always provide a nice meme