Computer Science, asked by adityaaneja7, 7 months ago

Problem Description
A permutation Pis such an array, such that all integers from 1 to P are present in it, exactly once
For example,
[2, 1. 3] and [3, 2, 1, 4, 5] are permutations.
[1, 2, 2]. (1, 3) and (4, 4] are not permutations.
For a permutation P, an index iis said to be good if for all indices that are less than i. Plj] <P[i] holds true
Or in other words, an index is said to be good, if the element at that index is greater than all its previous elements
For example,
• For the permutation (3, 2, 1, 4, 5), the indices 1, 4 and 5 are good indices. (There is 1-based indexing)
For the permutation (2, 1, 3), the indices 1 and 3 are good indices. (There is 1-based indexing)
Your task is to find the lexicographically smallest permutation of size A which has exactly B good indices.
A permutation P of size N is lexicographically smaller than some permutation of size , if there exists some indexi (1=1c-Neuchman
P] <QG]
P[1] = Q[1], P[2] = 0[2]. ...... Pſi - 1] = Q[1 - 1]​

Answers

Answered by sumitbauri252
0

Google search you will get the answers

Answered by saikumartadi7
1

Answer:

iterate through the array and find the largest element and place it in the Bth position  and then all the elements from 1 to B-1 can be placed to the left of it iterating through the array again . now sort the array from 1 to B-1 and then B+1 to P in order to get the lexicographically shortest permutation . we place largest element in Bth position because we want to make all the indices after be non good indices . if largest element is present in Bth position then all the indices to the right of it cannot be good indices

Explanation:

Similar questions