Thursday, October 03, 2019

How to prepare for technical interviews

You would find tons of information on how to go about preparing for software coding interviews. When you start preparing for coding interviews, there's no silver bullet to tackle the wide variety of interviews.

In general, the basic philosophy of big technology firms like Google, Amazon et. al is that they expect engineers to know a little bit about everything and everything about something. 

I've failed in my interviews with Google, Amazon and Microsoft at different points in my career, but, I've sailed quite smoothly in other seemingly "highly selective" organisations. I'll cover my interview experience with Google in some other post, but, my intention here is to consolidate and elaborate on what I think could be a good strategy to go about preparing for those big tech giants as I move towards the same.

Let's explore few key points and strategies to tackle technical interviews.

  1. Learn from your work:  This is the most understated point when it comes to landing your dream job. It is quite obvious that we have a huge area to cover when it comes to preparing for interviews. We really can't focus on everything in the limited time (say a few months/weeks) we have for  the prep. The key lies in the fact that majority of who you are as an engineer is driven through the work you've done so far.

    Its usually a good idea to have a top down approach towards understanding a project. Its equally important to ask the right questions.

    Few questions to tackle when you are working on a big project at work.

    - What problem is this software stack solving?
    - What is the high level architecture of this solution?
    - What part of this software stack am I responsible for?
    - What could have been alternate solutions to solve this problem?

    While above is not an exhaustive list, its indicative of the approach to streamline the effort to better grasp what you are doing.
  2. Practice your Data structures & Algorithms:
    This is a no-brainer when it comes to preparing for the coding interviews. There are plenty of resources when it comes to picking up practice material, but, its important to stick to one good resource and stay consistent with your preparations.

    In my experience, consistency and discipline outweighs brilliance when it comes to creating results. Read about plasticity and growth mindset. 

    Here's one viable plan that worked for me, and you could expand on it.
    - Write down all the topics you need to cover for your preparation.
    - Solve at least one problem each day, this is very important, believe me our mind requires daily dose of these exercises to really fire up.
    - Don't rush to look for the solution, at the same time, don't get bogged down by the problem. Take your time to solve the problem, if you still can't unblock yourself and understand the underlying concept. But, you should at least once, sleep over that problem. Let your subconscious mind kick into problem solving.
    I'll write some good resources for preparing for coding interviews.
  3. Work on your System Design/Large Scale systems: 
    All tech intensive jobs interviews expect you to have good understanding of System Design and Back-of-the-envelop calculations. This is expected more from someone having experience in the industry. It really doesn't matter if you have worked on such a systems or not.

    These interviews usually provide you with a fairly open-ended and vague problem description. e.g. Design a system to monitor files and directory sizes in a data-centre.

    These interviews are there to test your approach towards few of the key skills.
    - Communication skills: How well you articulate your understanding of the problem and how well you extract the information from the interviewer to solve the problem. Its more of a collaborative effort between the candidate and the interviewer to workout a solution where candidate is the driver.
    - Engineering Design Skills: As they say, there's no perfect design. But, the designs should be flexible enough to cater to the future requirements. Its very important to first understand the requirements (functional/scalbility etc) and convey to the interviewer about your understanding. Jumping straight towards the whiteboard to pour your initial thoughts is a sign of immaturity. Think aloud and talk about choices with your justification. Keep reading about large scale systems like Google search, Netflix, Uber etc. There are pretty cool technologies these organisations have developed and its always a good idea to get an understanding of them.

Below are some of the good references for interview preparation.

Wednesday, October 02, 2019

Minimum Difference Between BST Nodes


This is one of the easier problems to test your Data structures knowledge. I picked
it up from leetcode.

Here's the problem statement:

Given a Binary Search Tree (BST) with the root node root,
return the minimum difference between the values of any two different nodes in the tree.

example:
For the following given binary search tree
                       4
                     /   \
                  2       6
                /   \
              1      3

The minimum difference is 1, between nodes with value 1 and 2 as well as between
nodes with values 2 and 3.

Idea 1:
Iterate over the BST in an inorder fashion and save the numbers in a vector.
The smallest difference is going to be between two adjacent numbers.

Idea 2:
Another idea to attack the problem is to utilize the fact that if we do an in-order
traversal of the BST, we'll get the values in ascending order. 

Based on idea 2 above, we'll employ recursive in-order solution and augment the algorithm to keep two more 'facts' (invariants) at each state of the recursion-tree

  • What is the value of the predecessor we've seen, to compare with the current value
  • What is the minimum difference seen so far.
Following is the solution: