Tip 1: Complete 500 high-quality questions.
Tip 2: Have a few solid projects on your resume.
Tip 1: Include some projects on your resume.
Tip 2: Do not include false information on your resume.
Timing: 8 to 9 PM.
How was the environment? It was decent.
How was the interviewer? They were a nice person.



Here, we need to find the next permutation of an array. For example, [2, 1, 3, 4] is lexicographically smaller than [2, 1, 4, 3].



If the given array is [ 2, 3, 1], we need to return [1, 1, -1]. Because for 2, 1 is the Next Smaller element. For 3, 1 is the Next Smaller element and for 1, there is no next smaller element hence the answer for this element is -1.
I used the stack concept to solve this question.
What is a Map? Explain how an ordered Map works, etc. (Learn)



1. For all such levels where there is only one corner node the leftmost and the rightmost nodes are the same.
2. In the output, you have to print the leftmost and rightmost values in level order fashion i.e, the leftmost node of level1 followed by the rightmost node of level1 followed by the leftmost node of level2 followed by the rightmost node of level2 and so on.
Using level-wise order traversal, we will maintain a queue to store the pending nodes. Starting from the 0th level, i.e., the root node, we will add the root node to the queue. For each level stored in the queue (initially, we have the 0th level), we will poll nodes one by one from the queue and add the corresponding children to the queue. While popping nodes, we will also print the first (leftmost) and last (rightmost) nodes of that level. This way, we will have another level pending in the queue to traverse. This process continues until the last level is traversed (see the algorithm below for the approach).

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?