We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Ashton and String

Ashton and String

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Ashton appeared for a job interview and is asked the following question. Arrange all the distinct substrings of a given string in lexicographical order and concatenate them. Print the character of the concatenated string. It is assured that given value of will be valid i.e. there will be a character. Can you help Ashton out with this?

For example, given the string , its distinct substrings are . Sorted and concatenated, they make the string . If then, the answer is , the character of the 1-indexed concatenated string.

Note We have distinct substrings here, i.e. if string is aa, it's distinct substrings are a and aa.

Function Description

Complete the ashtonString function in the editor below. It should return the character from the concatenated string, 1-based indexing.

ashtonString has the following parameters:
- s: a string
- k: an integer

Input Format

The first line will contain an integer , the number of test cases.

Each of the subsequent pairs of lines is as follows:
- The first line of each test case contains a string, .
- The second line contains an integer, .

Constraints



Each character of string
will be an appropriate integer.

Output Format

Print the character (1-based index) of the concatenation of the ordered distinct substrings of .

Sample Input

1
dbac
3

Sample Output

c

Explanation

The substrings when arranged in lexicographic order are as follows

a, ac, b, ba, bac, c, d, db, dba, dbac

On concatenating them, we get

aacbbabaccddbdbadbac

The third character in this string is c.

Author

amititkgp

Difficulty

Advanced

Max Score

100

Submitted By

12657

Need Help?


View discussions
View editorial
View top submissions
RESOURCES

  • Suffix Array
  • LCP Array

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy