Tip 1 : Understand the logic behind each solution properly. Don’t memorize it.
Tip 2 : Practice more
Tip 3 : Practice explanation skills
Tip 1 : Be concise and to the point
Tip 2 : Presentable
( HackerEarth platform) - two questions were there. I solved 1 out of them. One was easy-medium (dfs, bfs based) and the second was the array based question.
It had a time slot of 2 days, I could give any time in that 2 days.



In the below map of Ninjaland let say you want to go from S=1 to T=8, the shortest path is (1, 3, 8). You can also go from S=1 to T=8 via (1, 2, 5, 8) or (1, 4, 6, 7, 8) but these paths are not shortest.

One solution is to solve in O(VE) time using Bellman–Ford. If there are no negative weight cycles, then we can solve in O(E + VLogV) time using Dijkstra’s algorithm.
Since the graph is unweighted, we can solve this problem in O(V + E) time. The idea is to use a modified version of Breadth-first search in which we keep storing the predecessor of a given vertex while doing the breadth-first search.
We first initialize an array dist[0, 1, …., v-1] such that dist[i] stores the distance of vertex i from the source vertex and array pred[0, 1, ….., v-1] such that pred[i] represents the immediate predecessor of the vertex i in the breadth-first search starting from the source.
Now we get the length of the path from source to any other vertex in O(1) time from array d, and for printing the path from source to any vertex we can use array p and that will take O(V) time in worst case as V is the size of array P. So most of the time of the algorithm is spent in doing the Breadth-first search from a given source which we know takes O(V+E) time. Thus the time complexity of our algorithm is O(V+E).



We cannot use the element at a given index twice.
Try to do this problem in O(N) time complexity.
It was problem solving round only
it happened at 5 pm



You may assume that duplicates do not exist in the given traversals.
For the preorder sequence = [1, 2, 4, 7, 3] and the inorder sequence = [4, 2, 7, 1, 3], we get the following binary tree.




1. A complete binary tree is a binary tree in which nodes at all levels except the last level have two children and nodes at the last level have 0 children.
2. Node ‘U’ is said to be the next node of ‘V’ if and only if ‘U’ is just next to ‘V’ in tree representation.
3. Particularly root node and rightmost nodes have ‘next’ node equal to ‘Null’
4. Each node of the binary tree has three-pointers, ‘left’, ‘right’, and ‘next’. Here ‘left’ and ‘right’ are the children of node and ‘next’ is one extra pointer that we need to update.


It was DS + projects
The interviewer was Dev's manager. Didn't ask me to write full code. Just pseudo code.
And full code for heapify function.



If two words have the same frequency then the lexicographically smallest word should come first in your answer.
Can you solve it in O(N * logK) time and O(N) extra space?
What if the data size is too large and can not store in memory, ie. stored in a file and you are getting input as a stream. Given approach like dividing the file into smaller parts ( multi hashmap + heap)
10 mins discussion about current work .
It was core problem solving and coding



If there are any duplicates in the given array we will count only one of them in the consecutive sequence.
For the given 'ARR' [9,5,4,9,10,10,6].
Output = 3
The longest consecutive sequence is [4,5,6].
Can you solve this in O(N) time and O(N) space complexity?



If any live cell has less than two live neighbors, then it dies.
If any live cell has two or three live neighbors, then it lives onto the next generation.
If any live cell has more than three live neighbors, then it dies.
A dead element with exactly three live neighbors becomes a live element.
Your task is to print the next state of this board using these four rules.
2 Behavioral Questions + 1Technical
Tell me an instance where your manager told you “ Dont do this”.



1. get(key) - Return the value of the key if the key exists in the cache, otherwise return -1.
2. put(key, value), Insert the value in the cache if the key is not already present or update the value of the given key if the key is already present. When the cache reaches its capacity, it should invalidate the least recently used item before inserting the new item.
Type 0: for get(key) operation.
Type 1: for put(key, value) operation.
1. The cache is initialized with a capacity (the maximum number of unique keys it can hold at a time).
2. Access to an item or key is defined as a get or a put operation on the key. The least recently used key is the one with the oldest access time.
Tell me the time when you entered into an argument with the team
A story-based question was there like A plant is there. It will drop two seeds one on left and one on right. Any one or both of them can convert to grown-up plants. Then again they will drop seeds left and right.
Finally boils down to a full binary tree is there. Any node is either plant or empty space (NULL). At any level length of pipes required to water the plant is the distance between the left most node ( grown-up plant ) - the rightmost node (grown-up plant).
The main focus was on how will you store the full binary tree representation. if you make a tree. Let's say n (number of levels) is too high. Eg 1000. How much memory it will consume. Is it feasible for a much larger n?
Finally, I took the approach. I will store it in a file in a serialized tree manner.
https://leetcode.com/problems/serialize-and-deserialize-binary-tree/
They will traverse level by level and calculate the value required for each level.

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?