Recently after graduating from college in may'19, I applied for SDE-I role at mindtickle through employee referral. I got a call within 1-2 days from HR and she checked my interest for role, and scheduled a Skype/google hangout round 2-3 days later. The HR was quite supportive throughout the process and all the round-scheduling was done according to my comfort-ability and availability.(except Saturday/Sunday :p)
Round 1: Skype/Hangout round
This round was basically a DSA round with interviewer asking some questions from my CV. So it started with a small discussion on my internship project and some easy follow-up questions. This was the easiest round of all.Then he asked me one algorithm question-
- Given a list of n*2 values with n representing days, 1st column will represent points collected after doing easy task, 2nd column will represent points for hard task, our task is to maximize the points collected after n days, with a given condition that if a person performs hard task on day 'i', he has to take a break on day 'i+1', i.e., he should perform no work on next day. Also he can do either easy or hard task. I gave him a dp solution with explanation, for which he seemed satisfied. He asked me to write full working code for it on a link shared through collabedit and then he dry run code on several edge cases. After he asked if I had any questions for him, to which I asked about the job profile and he explained about different job roles at mindtickle .
- Given an array, generate any random equiprobable permutation for this array and do it in place. I proposed the solution by using simple random function for every index and created new array by swapping, to which he was satisfied.
- Next he asked given a Binary Tree, shuffle the tree nodes randomly maintaining its structure. I gave the solution by traversing the tree and storing it in an array (say in-order), and will apply the approach of question-1 on the array, then will again replace the tree values(in same order traversal) with the shuffled array. He asked time complexity, space complexity, I said both are o(n). He made me to write full working code for this approach on collabedit and dry run several cases.
- Next he said that in above given question, reduce the space complexity to constant, and do not worry about the time complexity. I was struck around the question for a while, to which he hinted to use both question-1 and question-2 logic. After around 5 minutes, I gave him o(n^2) solution, in which I traversed the tree for every node, generated a random node number for this node, and maintained the count for traversal from the root, so when the count will be equal to that random generated number, I swapped both nodes data.
- Given a sorted array of integers, and a func f=ax^2+bx+c, where a, b, c can be any integers, x is array values, generate the sorted array for func. f. I said directly calculate values of 'f' for all input array, and then sort the created array. He agreed and asked the time complexity. I replied with o(nlogn). He asked me to reduce the time complexity to o(n). I thought for 5 minutes and gave him a 2 pointer approach. The solution is- since f is parabolic, it will be either upward opening or downward opening. Let us consider upward opening. now, the point where D=0 for a parabola is x=(-b/2a), I binary-searched it on input array, and told that f(x) for values greater than this x will be increasing order, and all f(x) less than this x point will be also in increasing order. So we will take 2 pointer, one for right part of this x, other for left part of this x, and compare their f(x) and increment the pointers accordingly(remember here I am only considering upward facing parabola). Similarly can be done for downward facing parabola. He then asked me to write full working code for this and checked the code for cases.
- Given a stream of requests on a server capable of processing only 'n' requests, find the probability that every incoming request will have equal probability in those 'n' processing requests. You can refer to following - https://www.geeksforgeeks.org/dsa/reservoir-sampling/ . I was not able to do this as I was not familiar with this type of algorithms(randomized algorithm). He asked me this because I had done a ML project in my college time.
- Some easy probability questions.
- 1. Given an array find its median and little error in answer is acceptable(Alert - Hint !!). I said simply sort the array and find the middle element. He asked time complexity. I said nlogn. He said to reduce it to o(n). He gave the hint to use the above discussion. I told him, we can create a binary tree with property that parent is greater than left child, lesser than right child. And we will keep this tree balanced. The root will be median. He was impressed by the use of above knowledge, but insisted that time complexity is still not o(n). After 5-10 minutes, he asked me that whether I have heard of a randomized algorithm, median of a median. You can google it and can find it easily. Since I had no knowledge about this, we proceeded to next question.
- 2. A simple question on Dijkstra. He asked me then to prove that why Dijkstra is greedy.(by induction or contradiction, and I proved it with contradiction).
- 3. Some follow-up questions on my second year summer project.