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 Specification

The first line will have the string.

The second line will have K.

Output Specification

Print the lexicographically least substring of length at least K.

Sample Input


Sample Output



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

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

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

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

      • 0
        31501357  commented on Aug. 14, 2020, 3:06 a.m.

        Oh yeah.

      • 34
        p1geon  commented on Jan. 17, 2020, 2:26 a.m.

        He a little confused, but he got the spirit.

  • 7
    bobhob314  commented on Dec. 25, 2014, 4:25 p.m.

    Python hax always provide a nice meme