Find the number
Practice
1.9 (17 votes)
Permutation and combination
Set
Java
Python 3
Python
Medium
Algorithms
Searching algorithm
Linear search
Java 8
String
Problem
64% Success 2939 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string \(S\) of length \(N\)  . The string \(S\) consists of digits from 1-9. Consider the string indexing to be 1-based.
You need to divide the string into blocks such that the \(i^{th}\)  block contains the elements from the index\( ((i-1)*X + 1)\) to \(min(N,(i*X))\) (both inclusive). A number is valid if it is formed by choosing exactly one digit from each block and placing the digits in the order of their block number.

For example:

If the given string is '123456789' and X=3, the blocks formed are [123], [456], [789]. Few valid numbers are 147,159,348 etc.. but 124 and 396 are invalid.

Among all the valid numbers that can be formed, your task is to determine the \(K^{th}\)number if all the unique valid numbers are sorted in ascending order.

Input format

  • First line: Three space-separated integers \(N, X,\) and \(K.\)
  • Second line: String \(S\) consisting of digits (1-9).

Output format

  • Print the \(K^{th}\)  valid number.

Constraints

  • \(1 \le N,X \le 10^{5}\)  
  • \(1 \le K \le 10^{18}\)

Note: Value of \(K\) will always be such that answer exists.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
StringBasics of bit manipulationBasic ProgrammingBit manipulationBasics of Bit ManipulationLogic-BasedEasyBit Manipulation
Points:30
32 votes
Tags:
ReadyAlgorithmsMediumOpenApproved
Points:30
1 votes
Tags:
OpenOpenOpenImplementationBasic ProgrammingArraysEasyBasics of Implementation
Editorial

Login to unlock the editorial