Question 99
0
Find the number
0
You are given a string S of length N . The string S consists of digits from 1-9. Consider the string inde
You need to divide the string into blocks such that the ith block contains the elements from the ind-
min(N, (i + X)) (both inclusive). A number is valid if it is formed by choosing exactly one digit from
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 numbe
but 124 and 396 are invalid.
kth
number if all th
Among all the valid numbers that can be formed, your task is to determine the K
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
kth
valid number
![](https://hi-static.z-dn.net/files/dbd/8a8ba0fba795dd8ff744992e32bf75b0.png)
Answers
Answer:
Digits from 1-9 and digits can't repeat. ... Also number of digits in output is one more than number of characters in ... void PrintMinNumberForPattern
Explanation:
banefit for you
void solve(string s, int n, int x, int k) {
vector<string>v;
int idx = 1;
string temp = "";
for (int i = 1; i <= n; i++) {
if (i < min(n, idx*x)) {
temp.push_back(s[i-1]);
}
else {
temp.push_back(s[i-1]);
sort(temp.begin(), temp.end());
// cout << temp << " ";
v.push_back(temp);
temp = "";
idx++;
}
}
int m = v.size();
int arr[m];
for (int i = 0; i < m; i++) {
arr[i] = v[i].length();
}
for (int i = m-2; i >= 0; i--) {
arr[i] = arr[i] * arr[i+1];
// cout << arr[i] << " ";
}
int last = arr[m-1];
for (int i = 0; i < m; i++) {
arr[i] = arr[i] / last;
// cout << arr[i] << " ";
}
string ans = "";
k = k-1; //convert to based 0 index
for (int i = 0; i < m; i++) {
int t = k / arr[i];
string curr = v[i];
ans.push_back(curr[t]);
k = k % arr[i];
// cout << ans << " ";
}
cout << ans << endl;
}
//solve("132456978", 9, 3, 6);
//O/p: 159
For further reference refer to:
https://brainly.in/question/12809215
#SPJ3