Tip 1: Practiced topic-wise CodeStudio questions from the basics.
Tip 2: Watched numerous system design mock interviews.
Tip 3: Conducted mock interviews with friends for DSA and system design rounds.
Tip 1: Include some projects on your resume.
Tip 2: Do not include false information on your resume.



Can you do the above task in a minimum number of comparisons?
This can be solved by simply traversing the array once and updating the max and min by comparing it with every element. Steps :
1. Initialize min and max with the value of the first element of the array
2. Run a loop from index 1 to n-1 :
For every element, compare it with max and min. Update max and min accordingly.
This approach has O(n) time complexity and O(1) auxiliary space.


1. The first character of the string is guaranteed to be an integer which denotes the root element of the tree.
2. This is followed by zero, one or two pairs of parenthesis, which contains a child binary tree with the same structure.
3. The first parenthesis denotes the left child of the binary then the right child.
Let str= “1(2)(3)”
The tree will be:

The first element i.e 1 is the root node and the first bracket signifies the left child of the root node which has only 1 element i.e 2 and the second bracket signifies the right child of the root node that has only 1 node i.e 3 . Hence we have the binary tree as shown above.
The idea here is to repeatedly find out the children of a particular node, attach them with their 'PARENT' node and work on the child nodes separately.
This can be achieved by:-
Find out the 'ROOT' node by searching for ‘-1’ in the given 'PARENT' array. Pass this 'ROOT' node as well as the 'PARENT' array into a helper function. The helper function returns us the final 'ROOT' of the binary tree by doing the following things:- If the 'ROOT' is 'NULL', i.e. we are given the 'PARENT' array of a 'NULL' tree, returns 'NULL'. Otherwise, traverses the 'PARENT' array and finds out the children of the current 'ROOT'. Let us store 'LEFT' child in 'FIRST' and 'RIGHT' child in Second. Assigns 'FIRST' to the 'LEFT' child of 'ROOT' and recursively calls for the creation of subtree which has 'FIRST' as its 'ROOT'. Assigns Second to the 'RIGHT' child of 'ROOT' and recursively calls for the creation of subtree which has Second as its 'ROOT'. Return the 'ROOT' fetched from the helper function.



Here, we need to find the next permutation of an array like this
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.



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-order traversal, we will maintain a queue to store the pending nodes for traversal. Starting from the 0th level (i.e., the root node), we add the root node to the queue. For each level stored in the queue (initially, we have only the 0th level), we will poll nodes one by one from the queue and add their corresponding children to the queue. While polling nodes, we will also print the first (leftmost) and last (rightmost) nodes of that level. This way, we will have the next level pending in our queue to traverse. This process continues until the last level is traversed. The approach is outlined in the algorithm below.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
How do you remove whitespace from the start of a string?