Sir, I solved this problem using two arrays, one keeping positions of all the elements, and other is the original array.
Then I ran a while loop, until k=0 or until all the numbers are in their position to create the max number.
How can I use STL in this question.
STL approach for this question?
You have done it in right way using arrays. Vector could have been used, so has been given in STL category, but really no need of that.
1 Like
Let us say that n numbers can be in range [ 1, 10^9 ] then you could have used an ordered map with key-value pair as <number, position>. But in given problem n numbers will be from 1 to n so we can use array for that.
The fact that there will exist a constant or logn factor of fetching from map but that is not in case of array hence, its better to use array than map wherever possible.
1 Like