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 had 2 questions to solve under 90 minutes . Both the questions were of easy
to medium level of difficulty .
1 2 3
4 5 6
For the above 2*3 matrix , possible paths are (1 2 3 6) , (1 2 5 6) , (1 4 5 6).
You can return the paths in any order.
Approach :
Let ‘allAllPaths(n, m, edges, src, des)’ be the function that returns a 2D array that contains all the possible paths.
1) Take the following variables: 2D array ‘Graph’, to store graphs and ‘Visited’ array to mark each node whether it is visited or not.
2) Clear graph, initialize the visited array to false.
3) Run a loop from 0 to 'm' :
Add the undirected edge between edges[i] [0] and edges[i][1].
4) Take an 2D array 'allPaths' to store the answer.
5) Take an array 'currPath' to store the current path.
6) Push ‘src’ in ‘currPath’ and mark visited[src] equal to true.
7) Make a dfs(n, allPaths, currPath, src, des, graph, visited) and call the dfs function.
8) Return ‘allPaths’.
TC : O(N ^ N), where N = number of vertices
SC : O(N ^ N)
Approach :
1) Run loop until all the squares of loops are printed.
2) In each outer loop traversal push the elements of a square in a clockwise manner.
3) Push the top row, i.e. Push the elements of a kth row and increase k..
4) Push the right column, i.e. Push the last column and decrease the count of columns.
5) Push the bottom row, and decrease the count of rows.
6) Push the left column, and increase the count of the starting column index.
TC : O(N*M), where N = number of rows and M = number of columns
SC : O(1)
This round had 2 coding questions , the first one was related to Dynamic Programming and the second one was of Binary Trees. I first explained the approach with proper complexity analysis and then moved on to code both the solutions.
You can’t engage in multiple transactions simultaneously, i.e. you must sell the stock before rebuying it.
Input: N = 6 , PRICES = [3, 2, 6, 5, 0, 3] and K = 2.
Output: 7
Explanation : The optimal way to get maximum profit is to buy the stock on day 2(price = 2) and sell it on day 3(price = 6) and rebuy it on day 5(price = 0) and sell it on day 6(price = 3). The maximum profit will be (6 - 2) + (3 - 0) = 7.
Approach :
1) We initialize two 2-D matrices, buy[K+1][N+1] and sell[K+1][N+1].
2) Here, buy[i][j] will denote the maximum profit we can get in at most ‘i’ transactions from the array starting from index 0 and ending at index j -1 and the final state is buying the stock.
3) sell[i][j] will denote the maximum profit we can get in at most ‘i’ transactions from the array starting from index 0 and ending at index j -1 and the final state is not holding the stock i.e. selling the stock.
4) We iterate the matrix buy and sell column-wise and update the values.
4.1) buy[j][i] = max(buy[j][i-1], sell[j-1][i-1] - PRICES[i-1]). Here buy[j][j-1] denotes holding the stock and sell[j -1][i - 1] - PRICES[i -1] denotes buying the stock on i-th day.
4.2) sell[j][i] = max(sell[j][i-1], buy[j][i-1]+PRICES[i-1]). Here sell[j][i-1] denotes not holding the stock and buy[i][j - 1] + PRICES[i -1] denotes selling the stock on i-th day.
5) Finally return sell[K][N].
TC : O(N*K), where N = size of the array and K = max number of transactions allowed
SC : O(N*K)
Consider lines at an angle of 135 degrees(with respect to standard X- axis) in between nodes. Then, all nodes between two consecutive lines belong to the same diagonal
The diagonal traversal for the above tree is:
0 2 6 1 5 3 4 7
Approach :
1) Assign the diagonal number of the root as 0.
2) Do a preorder traversal of the binary tree and for each node keep track of the diagonal number.
2.1) Insert the value of the current node in the Map with the key as the diagonal number of the current node.
2.2) Now increase the diagonal number by 1 for the left child of the node and recursively traverse the left subtree.
2.3) Recursively traverse the right subtree and keep the diagonal number the same as the current node.
3) Initialize an empty array to store the diagonal traversal, let’s say 'traversal'
4) Iterate through the Map and add all the values of the Map to 'traversal'.
5) Finally, Return 'traversal'.
TC : O(N * log(N)) , where N = number of nodes in the binary tree
SC : O(N)
The interviewer asked 2 coding problems in this round followed by some questions from Operating System.
1. Each coin has a value associated with it.
2. It’s a two-player game played against an opponent with alternating turns.
3. At each turn, the player picks either the first or the last coin from the line and permanently removes it.
4. The value associated with the coin picked by the player adds up to the total amount the player wins.
'N' is always even number.
Ninjax is as smart as you, so he will play so as to maximize the amount he wins.
Let the values associated with four coins be: [9, 5, 21, 7]
Let’s say that initially, you pick 9 and Ninjax picks 7.
Then, you pick 21 and Ninjax picks 5.
So, you win a total amount of (9+21), i.e. 30.
In case you would have picked up 7 initially and Ninjax would have picked 21 (as he plays optimally).
Then, you would pick 9 and Ninjax would choose 5. So, you win a total amount of (7+9), i.e. 16, which is not the maximum you can obtain.
Thus, the maximum amount you can win is 30.
Let the values associated with four coins be: [20, 50, 5, 10]
Let’s say that initially, you pick 10 and Ninjax picks 20.
Then, you pick 50 and Ninjax picks 5.
So, you win a total amount of (10+50), i.e. 60.
In case you would have picked up 20 initially and Ninjax would have picked 50 (as he plays optimally).
Then, you would pick 10 and Ninjax would choose 5. So, you win a total amount of (20+10), i.e. 30, which is not the maximum you can obtain.
Thus, the maximum amount you can win is 60.
Approach :
1) The idea is to create a 2D table of size N*N.
2) Each entry in the table stores the solution to a subproblem i.e. ‘TABLE’['I']['J'] represents the maximum amount you
can win for the subarray ‘COINS’['I', 'J'] given that you start first.
3) The algorithm for filling the table is as follows :
Loop 1: For ‘LEN’ = 1 to ‘N’:
Loop 2: For ‘I’ = 0 to ('N' - ‘LEN’):
→Let 'J' = 'I' + ‘LEN’ - 1
→If ('I'+1) < N && ('J'-1) >= 0 then, A = ‘DP’['I'+1]['J'-1], otherwise A = 0.
→If (i+2) < N then, B = ‘DP’['I'+2]['J'], otherwise B = 0.
→ If ('J'-2) >= 0 then, C = ‘DP’['I']['J'-2], otherwise C = 0.
→ Update ‘DP’['I']['J'] = max(‘COINS’['I'] + min(A, B), coins['J'] + min(A, C)).
End Loop 2.
End Loop 1.
4) ‘DP’[0]['N'-1] stores the final answer.
TC : O(N^2) , where N = number of coins
SC : O(N^2)
Note: Since the number of ways can be very large, return the answer modulo 1000000007.
N=3
We can climb one step at a time i.e. {(0, 1) ,(1, 2),(2,3)} or we can climb the first two-step and then one step i.e. {(0,2),(1, 3)} or we can climb first one step and then two step i.e. {(0,1), (1,3)}.
Approach (Using DP) :
1) We reach “currStep” step in taking one step or two steps:
1.1) We can take the one-step from (currStep-1)th step or,
1.2) We can take the two steps from (currStep-2)th step.
2) So the total number of ways to reach “currStep” will be the sum of the total number of ways to reach at (currStep-
1)th and the total number of ways to reach (currStep-2)th step.
3) Let dp[currStep] define the total number of ways to reach “currStep” from the 0th. So,
dp[ currStep ] = dp[ currStep-1 ] + dp[ currStep-2 ]
4) The base case will be, If we have 0 stairs to climb then the number of distinct ways to climb will be one
(we are already at Nth stair that’s the way) and if we have only one stair to climb then the number of
distinct ways to climb will be one, i.e. one step from the beginning.
TC : O(N), Where ‘N’ is the number of stairs.
SC : O(N)
What are the different types of semaphores ?
There are two main types of semaphores i.e. counting semaphores and binary semaphores.
1) Counting Semaphores :
These are integer value semaphores and have an unrestricted value domain. These semaphores are used to
coordinate the resource access, where the semaphore count is the number of available resources. If the resources
are added, semaphore count automatically incremented and if the resources are removed, the count is decremented.
2) Binary Semaphores :
The binary semaphores are like counting semaphores but their value is restricted to 0 and 1. The wait operation only
works when the semaphore is 1 and the signal operation succeeds when semaphore is 0. It is sometimes easier to
implement binary semaphores than counting semaphores.
What is a deadlock in OS? What are the necessary conditions for a deadlock?
Deadlock is generally a situation where a set of processes are blocked as each process is holding resources and
waits to acquire resources held by another process. In this situation, two or more processes simply try to execute
simultaneously and wait for each to finish their execution because they are dependent on each other. We can see a
hand problem in our system whenever a deadlock occurs in a program. It is one of the common problems you can
see in multiprocessing.
Necessary Conditions for Deadlock
There are basically four necessary conditions for deadlock as given below:
1) Mutual Exclusion
2) Hold and Wait
3) No Pre-emption
4) Circular Wait or Resource Wait
This was a typical HR round with some standard Behavioral questions.
Tell me something not there in your resume.
If you get this question, it's an opportunity to choose the most compelling information to share that is not obvious from
your resume.
Example :
Strength -> I believe that my greatest strength is the ability to solve problems quickly and efficiently, which makes me
unique from others.
Abillity to Handle Pressure -> I enjoy working under pressure because I believe it helps me grow and become more
efficient .
Tip : Emphasize why you were inspired to apply for the job. You can also explain that you are willing to invest a great
deal of energy if hired.
These are generally very open ended questions and are asked to test how quick wit a candidate is. So there is
nothing to worry about if you have a good command over your communication skills and you are able to propagate
your thoughts well to the interviewer
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?