Getting run error in this question …my code is given below
Next Permutation
Given an array Arr[], Treat each element of the array as the digit and whole array as the number. Implement the next permutation, which rearranges numbers into the numerically next greater permutation of numbers. If such arrangement is not possible, it must be rearranged as the lowest possible order ie, sorted in an ascending order. Note: The replacement must be in-place, do not allocate extra memory. Input Format The First Line contains the Number of test cases T. Next Line contains an Integer N, number of digits of the number. Next Line contains N-space separated integers which are elements of the array ‘Arr’. Constraints 1 <= T <= 100 1 <= N <= 1000 0 <= Ai <= 9 Output Format Print the Next Permutation for each number separated by a new Line. Sample Input 2 3 1 2 3 3 3 2 1 Sample Output 1 3 2 1 2 3
hello @dhanshree_p18 try now https://ide.codingblocks.com/s/353932
if you feel that your doubt is cleared please mark this doubt as resolved .
Happy Learning !!
Its giving time limit exceeded error here in course section where we have to code but working fine on coding blocks ide
hey @dhanshree_p18 this is because you are using the inbuilt function and whose time complexity is more .
there can be optimised approach as well.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.