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.


The first line will have the string.

The second line will have K.


Print the lexicographically least substring of length at least K.

Sample Input


Sample Output



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

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

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

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

      • 1
        31501357  commented on Aug. 13, 2020, 11:06 p.m.

        Oh yeah.

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

        He a little confused, but he got the spirit.

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

    Python hax always provide a nice meme