Monk and Suffix Sort

0

0 votes
Sorting, Algorithms
Problem

Monk loves to play games. On his birthday, his friend gifted him a string S. Monk and his friend started playing a new game called as Suffix Game. In Suffix Game, Monk's friend will ask him lexicographically kth smallest suffix of the string S. Monk wants to eat the cake first so he asked you to play the game.

Video approach to solve this question: here

Input Format:
First line contains a string S (1|S|25) and an integer k (1k|S|).

Output Format:
Print the lexicographically kth smallest suffix of the string S.

Note:
Those who are not familiar with suffix and lexicographical order, can read about it from https://en.wikipedia.org/wiki/Suffix and https://en.wikipedia.org/wiki/Lexicographical_order.

Sample Input
aacb 3
Sample Output
b
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

All the suffices of the string are:
aacb
acb
cb
b

After sorting the order of the suffices will be:
aacb
acb
b
cb

3rd smallest suffix will be b.

Contributers:
Editor Image

?