Tip 1 : Be consistent
Tip 2 : Try interacting with the interviewer by sharing your approach to them
Tip 3 : Practice mostly asked DSA questions
Tip 4 : Always know the time complexity of your solution and try optimising your approach.
Tip 5 : Focus on building the logic instead of just cramming the solution.
Tip 1 : Do not put false things on resume
Tip 2 : Keep it short and simple
Timing was 1:00 PM. There were total 4 questions out of which 3 were coding questions and one was pointer based output question.



Assuming the linked list is 3 -> 2 -> 3 -> 4 -> 2 -> 3 -> NULL.
Number ‘2’ and ‘3’ occurs more than once. Hence we remove the duplicates and keep only their first occurrence. So, our list becomes : 3 -> 2 -> 4 -> NULL.
As the list was sorted so i used two pointer approach.
Eg: 1->2->2->3
p1=1 and p2=2 as the value of p1 and p2 is different so moving both the pointers.
p1=2 and p2=2 as the value of both the pointers are same so moving moving p2.
p1=2 and p2=3 as the value of p1 and p2 is different so now changing next of p1 to point to p2 and moving both the pointers.
p1=3 and p2=null as p2 becomes null so terminating the loop



Input:
‘ARR’ = [-6,-3, 2, 1, 5]
If we take a square of each element then the array/list will become [36, 9, 4, 1, 25].
Then the sorted array/list will be [1, 4, 9, 25, 36].
Output :
[1, 4, 9, 25, 36].
as the array was sorted so i used two pointer approach.
Eg: [-6,-1,5]
p1=-6 and p2=5 and result=[ , , ] so comparing p1 and p2 without including sign so p1 is greater so storing square of p1 in the result and moving p1 to next.
now p1=-1 and p2=5 and result=[ , ,36] so comparing p1 and p2 without including sign so p2 is greater so storing square of p2 in the result and moving p2 to prev.
now p1=-1 and p2=-1 and result=[ ,25,36] so comparing p1 and p2 without including sign so both are equal so storing square of p1 and moving p1 to next.
now p1=5 and p2=-1 and result=[1,25,36] as our pointers crossed each other or we can say our resultant array is filled so returning the result.



1
/ \
2 3
The root to leaf path 1->2 represents the number 12.
The root to leaf path 1->3 represents the number 13.
The total sum of all the possible root to leaf paths is 12+13 = 25
The output may be very large, return the answer after taking modulus with (10^9+7).
In this I used inorder traversal using recursion. Take a variable say v=0 at root. Now at each level multiple the value received by 10 and add the current nodes value. Repeat the same until reach the leaf node. When reach the leaf node add the currently formed value in the result.
Eg:
6
/ \
2 4
/ \ \
5 3 8
here v=0 at root(6) and result=0
now multiply v to 10 add current nodes value (root node=6) and pass to next level.
value received at 2nd level is 6. Multiply v to 10 add current nodes value (left node=2) and pass to next level.
value received for left sub tree (below 2) is 62. Multiply v to 10 add current nodes value (left node=5), v=625. As this is leaf node add this value to result.
And moving back to 2nd level and going to right sub tree of 2 value received is 62. Multiply v to 10 add current nodes value (right node=3), v=623. As this is leaf node add this value to result.
And so on for right sub tree of 6
Timing was 4:00 PM. There were total 4 questions all questions were coding questions.






Given 'N' : 5 (number of packets) and 'M' : 3 (number of students)

And chocolates in each packet is : {8, 11, 7, 15, 2}
All possible way to distribute 5 packets of chocolates among 3 students are -
( 8,15, 7 ) difference of maximum-minimum is ‘15 - 7’ = ‘8’
( 8, 15, 2 ) difference of maximum-minimum is ‘15 - 2’ = ‘13’
( 8, 15, 11 ) difference of maximum-minimum is ‘15 - 8’ = ‘7’
( 8, 7, 2 ) difference of maximum-minimum is ‘8 - 2’ = ‘6’
( 8, 7, 11 ) difference of maximum-minimum is ‘11 - 7’ = ‘4’
( 8, 2, 11 ) difference of maximum-minimum is ‘11 - 2’ = ‘9’
( 15, 7, 2 ) difference of maximum-minimum is ‘15 - 2’ = 13’
( 15, 7, 11 ) difference of maximum-minimum is ‘15 - 7’ = ‘8’
( 15, 2, 11 ) difference of maximum-minimum is ‘15 - 2’ = ‘13’
( 7, 2, 11 ) difference of maximum-minimum is ‘11 - 2’ = ‘9’
Hence there are 10 possible ways to distribute ‘5’ packets of chocolate among the ‘3’ students and difference of combination (8, 7, 11) is ‘maximum - minimum’ = ‘11 - 7’ = ‘4’ is minimum in all of the above.



The lists (1 -> 2 -> 1), (3 -> 4 -> 4-> 3), and (1) are palindromes, while the lists (1 -> 2 -> 3) and (3 -> 4) are not.
The second method used in this article can be used here. First we will reverse the second half
of the list and then we will have two pointers. First pointing to the head of the given list and
second point to the head of the linked list we reversed. Now we just need to merge the two lists
by changing their pointers alternatively.
Like in this case first our given list is 1->2->3->4->5->6->7->8
Now we reverse the 2nd half of the list and we have 2 lists as 1->2->3->4 and 8->7->6->5
Now we just need to traverse the list one by one and change their pointers.
You can use
Method 2 to find the middle element of the linked list and by storing the previous
element to mid you can make the next pointer of the previous element to mid to null. So there
will be no loops in the list after we reverse the second half and it will be much easier to traverse
both the lists.



Below is the example showing the input tree and its sum tree.

We will use BFS here and a variable l which will determine the level that we are traversing
and a sum variable that will store the sum of each level. Now here we have to consider that the
first 2 levels are always in AP.
So as AP is defined as a,a+d,a+2d,a+3d…….
When l=0 that is when we are at the root node we will store this value in a variable named ‘a’
and for this level we will store 0 in the resultant list/vector. Then when we are at l=1 that is level
1 we will store the sum of nodes at this level in the variable sum and (sum-a) into a variable
named ‘d’ and for this level we will store 0 in the resultant list/vector. Now when we are at l=2
that is at level 2 we will evaluate the sum of nodes at this level and store it in the variable sum
and from now on we will store ((a+(l*d)-sum) into resultant list/vector.
Timing was 10:00 AM. There were 4 rounds scheduled for one single day. There 3 technical interview and 1 HR. There were 2 question in each Technical interview.



Assuming, the linked list is 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> NULL. X = 2 and Y = 5. On reversing the given linked list from position 2 to 5, we get 10 -> 50 -> 40 -> 30 -> 20 -> 60 -> NULL.
For rotating the given sublist that extends from m to n element, move the list from (n-k+1)th to nth node to starting of sub-list to finish the rotation.
If k is greater than size of sublist then we will take its modulo with size of sublist. So traverse through list using a pointer and a counter and we will save (m-1)th node and later make it point to (n-k+1)th node and hence bring (n-k+1)th node to the start(front) of sublist.
Similarly we will save mth node and later make nth node point to it. And for keeping rest of list intact we will make (n-k)th node point to next node of n (maybe NULL). And finally we will get the k times right rotated sublist.



For the given binary tree

The reverse level order traversal will be {7,6,5,4,3,2,1}.
Timing was 1:00 PM.



The given linked lists may or may not be null.
If the first list is: 1 -> 4 -> 5 -> NULL and the second list is: 2 -> 3 -> 5 -> NULL
The final list would be: 1 -> 2 -> 3 -> 4 -> 5 -> 5 -> NULL
1. Start with head of both linked lists and find first common node. Use merging technique of sorted linked list for that.
2. Keep track of sum of the elements too while doing this and set head of result list based on greater sum till first common node.
3. After this till the current pointers of both lists don’t become NULL we need to adjust the next of prev pointers based on greater sum.



Suppose, Ninja is stuck at node 62. The possible exit points in the maze are: 40, 10, and 20. From all the possible exit points the closest ones are 10 and 20 which are at a distance of 1 unit.
My approach to this question was that first we can find if the node is in right subtree or left
subtree and store the the length of root to leaf of the other side of the tree.( If the given node lies
in the left sub tree simply store the maximum root to leaf path of right side and vice versa).
Second we need to calculate the length of path from root to given node.
Third we need to get the maximum distance of leaf nodes from the given node. (leaf nodes
under the given node).
Now we have 3 distances:
First: maximum distance of root to leaf node of other side
Second: distance of given node to root node
Third: maximum distance of given node to leaf node under given node
Now we can simply return max((first+second),third)
In the given example our given node lies in the right side of the given tree so values of
first=2
second=1
third=1
And the max of first+second and third is 3. So 3 is the answer
We can calculate first and second in single traversal and as we are given the node and not just
the value we can directly calculate third by using a simple recursive function.
Timing was 4:30 PM



1. It is not allowed to remove the whole array.
2. A subarray is defined as a contiguous block of elements in the array.
Suppose given ‘NUMS’ is [3, 1, 4, 2] and ‘P’ is 6.
The sum of the elements in ‘NUMS’ is 10, which is not divisible by 6. We can remove the subarray [4], and the sum of the remaining elements is 6, which is divisible by 6.
So print ‘1’ as a length of the removed subarray [4].



1. A binary tree is a tree in which each node has at most two children.
2. The given tree will be non-empty.
3. The given tree can have multiple nodes with the same value.
4. If there are no nodes in the tree which are at distance = K from the given node, return an empty list.
5. You can return the list of values of valid nodes in any order. For example if the valid nodes have values 1,2,3, then you can return {1,2,3} or {3,1,2} etc.

Consider this tree above. The target node is 5 and K = 3. The nodes at distance 1 from node 5 are {2}, nodes at distance 2 from node 5 are {1, 4} and nodes at distance 3 from node 5 are {6, 3}.
Timing of round was 8:30 PM
They asked me about my project. They asked some other questions like what I knew about the company, can I work extra hours like 10-12hrs, whether i have short temper, how will manage to travel to gurugram, etc.
Tip 1 : Be honest for every answer.
Tip 2 : Do study about the company beforehand.

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?