Tip 1 : Prepare basics, no one expects you to know hard topics
Tip 2 : Intra-personal skills are more important than solving the question
Tip 3 : Coding style is more important than the optimal approach
Tip 1 : Be thorough with whatever you have written in the resume
Tip 2 : For projects, focus on why and what rather than how
Online coding round
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.
‘0 <= i < j < N’.
‘ARR[i] > ARR[j]’.
‘0 <= i < N - 1’.
‘ARR[i] > ARR[i + 1]’
‘N = 6’
‘ARR’ = [2, 0, 1, 5, 6, 3]’
Pair of indexes that are global inversions: ‘(0, 1)’, ‘(0, 2)’, ‘(3, 5)’, ‘(4, 5)’.
Indexes that are local inversions: ‘0’, ‘4’.
Thus, you should return ‘False’ as the answer as the number of global inversions, and the number of local inversions is not equal.
1. All integers in ‘ARR’ are unique and ‘ARR’ is a permutation of the integers in the range [0, N - 1].
The interviewer was friendly, Gave a lot time to me to ask questions to her. Understood my projects and asked only one coding question. We had to write the code on a compiler, I used codechef compiler, if any error came, she gave time to correct the code and find out the error. She also pointed out my coding style and what could be improved to increase modularity in the code. She pasted an image for the test case as soon as the interview began
1. There is at least one cell having the integer 0 in the given matrix.
Consider the following 2*3 matrix ‘MAT’:
[0, 1, 1]
[0, 1, 1]
Here, the nearest cell having the integer 0 from the cell (0, 0) is the cell (0, 0) itself. The Manhattan distance between them is |0 - 0| + |0 - 0| = 0.
The nearest cell having the integer 0 from the cell (0, 1) is cell (0, 0). The Manhattan distance between them is |0 - 0| + |1 - 0| = 1.
The nearest cell having the integer 0 from the cell (0, 2) is cell (0, 0). The Manhattan distance between them is |0 - 0| + |2 - 0| = 2.
The nearest cell having the integer 0 from the cell (1, 0) is cell (1, 0) itself. The Manhattan distance between them is |1 - 1| + |0 - 0| = 0.
The nearest cell having the integer 0 from the cell (1, 1) is cell (1, 0). The Manhattan distance between them is |1 - 1| + |1 - 0| = 1.
The nearest cell having the integer 0 from the cell (1, 2) is cell (1, 0). The Manhattan distance between them is |1 - 1| + |2 - 0| = 2.
Thus we should return matrix:
[0, 1, 2]
[0, 1, 2]
Input: mat = [[0,0,0],[0,1,0],[1,1,1]]
Output: [[0,0,0],[0,1,0],[1,2,1]]
Input: mat = [[0,0,0],[0,1,0],[0,0,0]]
Output: [[0,0,0],[0,1,0],[0,0,0]]
Interviewer was a senior manager, not that frank, jumped directly to the questions and asked only one question. Asked to write the code on a google doc and asked me to explain the code fully before writing. While writing he asked my about different data structures that are widely used. For my solution, I was a little confused and gave a solution including various data structures, later on he gave me a hint and I solved the question within next 6 minutes.
insert(X): Inserts an element X in the data structure and returns true if the element was not present, and false otherwise.
remove(X): Removes the element X from the data structure, if present. Returns true if the element was present and false otherwise.
search(X): Search the element X in the data structure. Returns true if the element was present and false otherwise.
getRandom(): Return a random element present in the data structure.
Type 1: for insert(X) operation.
Type 2: for remove(X) operation.
Type 3: for search(X) operation.
Type 4: for getRandom() operation.
It is guaranteed that at least one element will be present in the data structure when getRandom() operation is performed.
Can you implement every operation such that it works in O(1) time?
Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
Which SQL keyword removes duplicate records from a result set?