Problems > The K-th Distinct Substring

The K-th Distinct Substring

Difficulty: 2400 6000 ms 128 MB

strings suffix-array

Among all DISTINCT substrings of S sorted lexicographically, print the K-th, or −1 if fewer than K exist.

Input: the first line has S; the second line has K.

Output: the K-th distinct substring, or −1.

Constraints:

  • 1 ≤ |S| ≤ 105
  • 1 ≤ K ≤ 1018

Sample Tests

Input 1
aba
3
Output 1
aba
Input 2
ab
5
Output 2
-1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.