Monk and Suffix Sort
Tag(s):

## Algorithms, Easy, Sorting

Problem
Editorial
Analytics

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 $k^{th}$ smallest suffix of the string S. Monk wants to eat the cake first so he asked you to play the game.

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

Output Format:
Print the lexicographically $k^{th}$ 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

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

$3^{rd}$ smallest suffix will be b.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), TypeScript, Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

CodeMonk (Sorting)

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > Sorting
• Algorithms > Sorting
• Algorithms > Sorting
• Algorithms > Sorting