Lexicographically Least Substring

View as PDF

Submit solution

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

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
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


  • -1
    31501357  commented on Jan. 16, 2020, 2:10 p.m.

    I did length of only K and passed, test cases are weak.


    • 16
      injust  commented on Jan. 16, 2020, 2:32 p.m.

      I think you might want to review the definition of lexicographical order.


      • 14
        p1geon  commented on Jan. 16, 2020, 9:26 p.m.

        He a little confused, but he got the spirit.


  • 7
    bobhob314  commented on Dec. 25, 2014, 11:25 a.m.

    Python hax always provide a nice meme