Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.
Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.
This was an online coding round where we were supposed to solve 2 questions under 90 minutes . Both the questions in my set were related to Graphs and were quite tricky and heavy to implement.



1. Include the source node as a destination also.
2. There are no cycles in the given graph.
Steps:
1) Create a recursive function that takes index of node of a graph and the destination index. Keep a global or a static variable count to store the count. Keep a record of the nodes visited in the current path by passing a visited array by value (instead of reference, which would not be limited to the current path).
2) If the current nodes is the destination increase the count.
3) Else for all the adjacent nodes, i.e. nodes that are accessible from the current node, call the recursive function with the index of adjacent node and the destination.
4) Print the Count.



If it is impossible to finish all courses, return an empty array. If there are multiple answers, return any one.
Input:
3 2
1 2
2 3
There are three courses to take. To start with, First course 3 is taken. Then course 2 is taken for which course 3 must be completed.
At last course 1 is taken for which course 2 must be completed. So the correct course order is [3,2,1].
Approach : This problem was based on Topological Sorting .
The first node in the topological ordering will be the node that doesn't have any incoming edges. Essentially, any node that has an in-degree of 0 can start the topologically sorted order. If there are multiple such nodes, their relative order doesn't matter and they can appear in any order.
Algorithm :
1) Initialize a queue, Q to keep a track of all the nodes in the graph with 0 in-degree.
2) Iterate over all the edges in the input and create an adjacency list and also a map of node v/s in-degree.
3) Add all the nodes with 0 in-degree to Q.
4) The following steps are to be done until the Q becomes empty.
4.1) Pop a node from the Q. Let's call this node, N.
4.2) For all the neighbors of this node, N, reduce their in-degree by 1. If any of the nodes' in-
degree reaches 0, add it to the Q.
4.3) Add the node N to the list maintaining topologically sorted order.
4.4) Continue from step 4.1.
This was a Data Structures and Algorithms round with some standard questions . I was expected to come up with an
efficient approach and code it as well .



For the given 5 intervals - [1, 4], [3, 5], [6, 8], [10, 12], [8, 9].
Since intervals [1, 4] and [3, 5] overlap with each other, we will merge them into a single interval as [1, 5].
Similarly, [6, 8] and [8, 9] overlap, merge them into [6,9].
Interval [10, 12] does not overlap with any interval.
Final List after merging overlapping intervals: [1, 5], [6, 9], [10, 12].
Steps :
1) First, we sort the list as described.
2) Then, we insert the first interval into our merged list and continue considering each interval in turn as follows -
2.1) If the current interval begins after the previous interval ends, then they do not overlap and we can
append the current interval to merged.
2.2) Otherwise, they do overlap, and we merge them by updating the end of the previous interval if it is
less than the end of the current interval.
TC : O(N*log(N))
SC : O(1)
Follow Up : Prove your Greedy solution .
A simple proof by contradiction shows that this algorithm always produces the correct answer. First, suppose that the algorithm at some point fails to merge two intervals that should be merged. This would imply that there exists some triple of indices i, j, and k in a list of intervals ints such that i < j < k and (ints[i],ints[k]) can be merged, but neither (ints[i],ints[j]) nor (ints[j],ints[k]) can be merged . We have following inequalities from this scenario :
ints[i].endints[j].endints[i].end≥ints[k].start
We can chain these inequalities (along with the following inequality, implied by the well-formedness of the intervals: ints[j].start <= ints[j].end ) to demonstrate a contradiction:
ints[i].end < ints[j].start ≤ ints[j].end < ints[k].start
ints[i].end ≥ ints[k].start
Therefore, all mergeable intervals must occur in a contiguous run of the sorted list.



1. If the move isn’t possible you remain in that cell only.
This was also a DSA round where I was asked to code only one of the questions but I eventually ended up coding both
as I had some spare time and explained my approches very smoothly to the interviewer . This round went preety well .



[1, 2, 3, 4] is a strictly increasing array, while [2, 1, 4, 3] is not.
Approach 1 (Using DP ) :
This is a classic Dynamic Programming problem.
Steps :
1) Let dp[i] is the longest increase subsequence which ends at nums[i] .
2) For every i from 0 to n , traverse backwards from j=i-1 to j=0 and check if nums[i]>nums[j].
3) If nums[i]>nums[j] , update dp[i]=max(dp[i] , dp[j]+1)
4) Finally return the maximum element from the DP array
TC: O(N^2)
SC: O(N)
Approach 2 (Using Binary Search and Greedy ) :
Steps:
1) Maintain a vector v (this will remain sorted at all times) .
2) Push the first element into the vector v.
3) Run a loop from 1 to n and for every element check if nums[i]>v.back()
4) If nums[i]>v.back() , simply push nums[i] into v .
5) Else , find the lower_bound position of nums[i] in vector v and replace that element with nums[i] .
6) Finally , the length of the vector v gives us the length of the LIS.
7) To get the final sequence we can maintain a path vector where path[i] stores the index of the previous number in LIS
TC : O(N*Log(N))
SC : O(N)



1. If ‘k’ is not present in 'arr', then print -1.
2. There are no duplicate elements present in 'arr'.
3. 'arr' can be rotated only in the right direction.
Input: 'arr' = [12, 15, 18, 2, 4] , 'k' = 2
Output: 3
Explanation:
If 'arr' = [12, 15, 18, 2, 4] and 'k' = 2, then the position at which 'k' is present in the array is 3 (0-indexed).
This was a preety standard Binary Search Question and I had solved this question before on platforms like LeetCode and CodeStudio . I was asked this question to test my implementation skills and how well do I handle Edge Cases .
Approach :
1) The idea is to find the pivot point, divide the array in two sub-arrays and perform binary search.
2) The main idea for finding pivot is – for a sorted (in increasing order) and pivoted array, pivot element is the only element for which next element to it is smaller than it.
3) Using the above statement and binary search pivot can be found.
4) After the pivot is found out divide the array in two sub-arrays.
5) Now the individual sub – arrays are sorted so the element can be searched using Binary Search.
TC : O(Log(N))
SC : O(1)
This was also a DSA round with 2 questions of Medium to Hard difficulty . I was expected to follow some clean code and OOPS principles to write the code in this round .



The rank of any element in ‘ARR’ is equal to the number of smaller elements than ‘ARR[K]’ on its left side.
Input :
Let ‘ARR’’ = [6, 2, 9, 7] and ‘X’ = 3.
We can see there are two smaller elements than ‘ARR[3]’ = 7 on its left side
Output: 2
Try to find rank in less time complexity than O(N), you may use some data structure to implement this.
Step 1- Making the ‘BST’ :
Let insert(TreeNode* <int> ROOT, int VAL) be a function which insert data into ‘BST’.
Now consider the following steps to implement the function :
Now iterate over the ‘ARR’ and feed vales in ‘ARR’ to insert to generate ‘BST’.
Step2 -Find Rank of ‘ARR[K]’ say ‘NUM’ from ‘BST’:
Let getRank(TreeNode* <int> ROOT, int NUM) be a function that returns the size of the left subtree of the node with the value ‘NUM’ or we can say Rank of ‘NUM’.
Now consider the following steps to implement the function :



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.
Approach :
Structure of an LRU Cache :
1) In practice, LRU cache is a kind of Queue — if an element is reaccessed, it goes to the end of the eviction order
2) This queue will have a specific capacity as the cache has a limited size. Whenever a new element is brought in, it
is added at the head of the queue. When eviction happens, it happens from the tail of the queue.
3) Hitting data in the cache must be done in constant time, which isn't possible in Queue! But, it is possible with
HashMap data structure
4) Removal of the least recently used element must be done in constant time, which means for the implementation of
Queue, we'll use DoublyLinkedList instead of SingleLinkedList or an array.
LRU Algorithm :
The LRU algorithm is pretty easy! If the key is present in HashMap, it's a cache hit; else, it's a cache miss.
We'll follow two steps after a cache miss occurs:
1) Add a new element in front of the list.
2) Add a new entry in HashMap and refer to the head of the list.
And, we'll do two steps after a cache hit:
1) Remove the hit element and add it in front of the list.
2) Update HashMap with a new reference to the front of the list.
Tip : This is a very frequently asked question in interview and its implementation also gets quite cumbersome if you
are doing it for the first time so better knock this question off before your SDE-interviews.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
Which keyword is used for inheritance?