Hello,
Welcome to Day 3 of DSA. We hope you were able to solve the Day 1 and Day 2 problems and allocated sufficient time for it. We have published one Youtube video explaining the thinking procedure of the Day 1 problem.
Check the Day 1 video solution here.
Now coming for Day 3,
The problem statement for Day 3 goes as follow,
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).
The replacement must be in place and use only constant extra memory.
Example 1:
Input:
nums = [1,2,3]
Output:
[1,3,2]
Example 2:
Input:
nums = [3,2,1]
Output:
[1,2,3]
Example 3:
Input:
nums = [1,1,5]
Output:
[1,5,1]
Example 4:
Input:
nums = [1]
Output:
[1]
Instructions
Take a pen and paper don’t rush to google it.
Come up with a Naive solution.
Try to optimize the solution further.
Try and submit your code here.
If you have not downloaded our official android application(Early Access), download it from here.
We are also coming up with study materials for DSA, which can help you clear your interviews. If interested in having one, don’t forget to fill this form.
Thank you for stopping by!