All Tracks Algorithms Sorting Problem

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: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

CodeMonk (Sorting)

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications