Hi Everyone,
Hope this post helps you guys. Had an onsite on 13th Jan with one of the microsoft teams in Redmond which consisted of 4 rounds of 45 mins each.
OA round was 3 questions in an hour which are pretty elementary.
Onsite round 1: First 10 minutes went into resume and behavioral discussions. Then interviewer asked this question.
Given an array of distinct postitive numbers and a target t, print all the combinations that sum to the given target.
For example array=[3,9,6,4,2,7] target = 12, output should be [2,4,6], [3,9], [3,7,2]. Classic knapsack type of problem, coded the brute force solution first no memoization or anything and just stored the partial result in a list, interviewer wanted me to dry run some test cases all of which passes. They also pointed towards a bug where my base case was wrong, quickly fixed it. No further questions on time complexity or memoization or anything
Next question: Write a singleton class in your preferred language, stumbled here as Ive been spoiled by DI annotations '@Singleton' from dagger/guice. But gave it a stab anyway, used a factor wrapper pattern with allowing only one instance of the class via the static factory method.
Example:
class SingletonProvider {
private SingletonProvider() {}
private ExampleClass obj;
public static ExampleClass getSIngletonClass()
{
if(obj == null) return new ExampleClass();
else throw WhateverException("");
}
}
Interviewer pointed out to dry run to which I found the bug in above code and rectified it like so:
class SingletonProvider {
private ExampleClass obj;
private SingletonProvider() {}
public static ExampleClass getSIngletonClass()
{
if(obj == null) {
obj = new ExampleClass();
return obj;
}
else throw WhateverException("");
}
}Onsite round 2: First 10 minutes went into resume and situational behavioral discussions again. Then interviewer asked this question.
Connect all leaves of a binary try as linked list. Asked clarifying questions on assuming the node structure having a next pointer, they said I could assume that. Then gave them the simplest solution of traversing the tree and storing leaf nodes in a list and finally connnecting them sequentally as post processing.
They went on to try do it with the extra O(N) space complexcity, which meant no temporary storage of leaf nodes.
Went on to reursive method, (interviewer was fine with implicit stack space), Didn't think too much about the solution and jumped straight into coding as I could see only 20 mins left on the clock, got the induction/hypothesis step(in normal tree questions wrong) where I was trying to be too smart and get left and right left nodes up the tree and connect them, kind of screwed it up lets say where it was as simple as just have a prev node leaf pointer as an when you encounter leaves in a postorder, preorder,inorder way.
Interviewere gave another question, with around 10 mins left on the clock. Find all the ancestores for a given tree node. Easy LCA question, coded it up and ran through all the test cases they provided by the last dying minute.
Onsite round 3:
More of a design a lift and ATM system but not explicitly told or could understand that it was an OOD question, jumped straight into solving again, on the LLD side, they wanted me to use linked list but I gave another approach and had discussion on how the API would be used depending on which if LL was even a necessity. FInally, coded up the linkedlist approach as well, they were hinting towards recursive soln along the lines of
f(i) = 1 + f(i-1)
where f(0) = 1;
The question was basically, whats my position int the ATM line. Didn't quite understand the problem statement here I feel but finally had consensus on the soln.
They interviewer went ahead with desiging a generic Cache class, which different cache classes having their concrete implementations of the cache interface methods. Coded up interface and concrete class as per the ask.
Was asked how would you add new API to the interface without breaking the existing clients, talked about Interface segregation princple(SOLID) and how a different interface would be added with the API method and the new concrete class could implement both the interfaces.
Follow up on why not use abstract class when you could need default implementation of methods, to which I explained that JAVA interfaces can have default methods. Interviewer wasn't quite convinced and pointed towards vitual functions(probably from the C++, C# background), to which I explained default methods in interface can achieve the same thing as a default non abstract public method in an abstract class in Java.
Next follow up was how interface was helping us keep the code extensible, gave some examples, talked about depdendency injection, was asked to code up a factory with singleton again, coded it.
Onsite round 4:
This round, can't go into too many details, but was basically a system design question but i took it as a simple leetcode question and kept solving it towards the very end, to which the interviewere finally said the logic was right but they meant more of a design aspect of things. In short, bombed it.
Final pointers and note to self:
Recruiter mentioned the probability of OOD and SD questions minimum hence I never prepared for it, was dumbfounded on many ocassions.
Should ask more clarifying questions, come up with more edge cases(I personally found imagining edge cases really hard), and have a proper conversation before jumping into solutions.
I would say the last interviewer was least collaborative and rude a bit If I could say that, felt like they hardly cared about the interview and told me in the end(in the last 10 mins) that it was not a leetcode style question, but its a bigger miss on my part as I didn't ask clarifying questions as probably should have.
Throughout the course of all rounds, they always asked my interest in backend v/s front end where I emphasized on front end inclination overall, and was asked if I had working at scale experience, to
which I always said I don't work at a huge scale at my current Job. I remember one of the interviewers mentioning they're specifically looking for people with experience at scale and that there is no front end work in the org. In hindsight, be tactical about how you portary your experience.
Overall, it was great and a humbling experience, lots to learn!!