How I cleared the Amazon SDE 2 interview

Rachit Gupta
6 min readDec 14, 2016

--

A recruiter found my profile on linkedin and informed me about an opening in Amazon for SDE 2 position. Just to provide a brief background on my profile, I am a graduate in computer science from IIT Bombay (India) and I had 4 years of experience in software development when I was given this opportunity.

Over the course of next 2 months I went through a telephonic screening round on programming, 3 on-site interviews with emphasis on design, one bar raiser round on people skills and software design followed by another round of programming interview. It was an exhaustive process to test me on all my skills and fortunately I was able to clear it.

As I went through the rounds it was apparent that work experience was not important. The stress was on the approach to solve questions and eventually come up with a working solution. There were several instances where only the approach was required and several others where implementation was required too. I had prepared for the same and would like to share the methods of preparation.

Before getting into the actual methods I would like to set the context with an analogy to fitness.

It is similar to saying you would want to get 6 pack abs. Can anyone get it? Yes, absolutely! Are there instructions on how to get it? Yes, again! The internet is filled with tips to get 6 pack abs. What’s the catch in this whole situation. The catch is that only a small subset of us work hard enough to really achieve it. It takes a hell lot of time, energy and will to accomplish something like that. You need to be fully invested in your quest and without that it would remain elusive.

Now to get 6 pack abs, all you need to do is follow a few simple steps

  • Buy membership of a gym and actually workout everyday
  • Get a personal trainer and listen to his advise
  • Start eating healthy and actually follow the diet plan
  • Give it a year and voila you have got what you wanted !

Sounds pretty simple right, but as you might know, not many can go to the gym regularly and that’s just the first step of the plan. Surprisingly learning software development is quite easy. You don’t need to buy a membership or leave the comfort of your house to be at the gym or listen to some guy telling you to give him another 5. All it takes is a laptop, a working internet connection, will to solve problems regularly and within a year you would learn the essentials.

Over the first 3 years of my job I did not practice coding and got a bit rusty. I even failed a couple of interviews which gave me the kick to polish my skills. I started with solving the basic problems on Leetcode and Hackerrank. I did not do it rigorously but I did it regularly. I tried to solve one problem everyday. It was either a new problem or something that I had solved earlier. Over the course of 8 months I solved 100+ problems multiple times. Eventually I was able to read the question and come up with perfect solution along with code in the first attempt.

I realized that attempting the same problem multiple times is vital to preparation. It is not an exercise in coding but an exercise in mental visualization. Solving them again in regular intervals makes you familiar with the data structures and helps to visualize them better. Once you get comfortable with visualizing them you will be able to manipulate them.

Let me demonstrate this with the following problem. Given an array of integers we need to move all the zeroes to the end and maintain the order of rest of the elements. Needless to say it should be an in-place solution. I have written 6 different solutions to this problem in an interval of 6 months. I have listed 3 here.

  1. Copy non-zero element to left, mark everything else zero
def moveZeroes(self, nums):
counter = 0
for i in nums:
if i != 0:
nums[counter]=i
counter+=1

for i in range(counter,len(nums)):
nums[i]=0

2. Learnt using tuples and one line if else

def moveZeroes(self, nums):
i = 0
for j in range(len(nums)):
nums[i],i= (nums[j], i+1) if nums[j]!=0 else (nums[i], i)
for k in range(i, len(nums)):
nums[k]=0

3. Used only one loop and reduced number of lines

def moveZeroes(self, nums):
j = 0
for i in range(len(nums)):
if nums[i]!=0:
nums[j], nums[i], j = nums[i], nums[j], j+1

Now let me list the takeaways from this exercise

  • There are numerous ways to solve a problem
  • First solution can definitely be improved in performance or code quality
  • Each solution requires a different technique or a different point of view
  • With each solution the mental visualization of the problem improves
  • With better visualization the coding speed increases

To construct complex programs you need to expand your knowledge of the building block i.e. data structures and have tools to manipulate these blocks i.e. algorithms. To gain expertise in using these tools and building blocks you need to construct lot of small pieces over and over until it becomes effortless. You will know that it has become effortless when after reading a problem you are able to write production quality code, covering all test cases, within a minute, on a paper and you know it is correct.

As you start making the small pieces over and over you will notice that the time taken to write them reduces dramatically. From well over 30 mins to less than 20 mins to 10 mins and eventually less than a minute. It is not because you have memorized the code. It is because you have memorized all possible scenarios of the question and re-creating them again will now be effortless.

I hope you have understood the how this approach works. Let’s move on to the road-map that will cover these required concepts. I believe if you can write solutions to these questions comfortably then you can crack your interviews comfortably.

Arrays

Remove, Search, Range Search, insert position, Rotate, Search in rotated, Max subarray, Set Matrix, Pascal’s Triangle, 2 Sum, 3 Sum, Single number, Intersection, Majority, Duplicates, Missing, Consecutive sequence, valid sudoku, plus one

Sorting

Bubble, Insertion, Counting, Quick, Merge

Heap

Kth largest in array, Kth smallest in matrix, Median, Ugly Number, Super Ugly Number

Strings

Reverse, First unique char, anagram, pallindrome, last word, common prefix, substring without repeating chars,

Numbers

Pallindrome, Power, Sqrt, Reverse, Happy number, Guess number, Next permutation, single

Linked Lists

Delete, Reverse, Remove, Cycle, Reverse range, Rotate, Partition, Merge, Swap Node, Add, Add one, Remove duplicates, Pallindrome, Odd-even

Binary Trees

Max depth, Min depth, Invert, Same, LCA, Level order, Inorder, Preorder, Postorder, Balanced, Symmetric, Validate, Paths, Path sum, Max path sum, Right side view, Flatten to linked list, Kth smallest, Next Right

Graphs

Islands

Dynamic Programming

Climb Stairs, House Robber, Combination Sum, Palindromic Substring, Max product subarray, Frog Jump, Coin Change, Unique Paths, LIS, minimum path sum

Design

Chess, Twitter, LRU cache, Swimming Pool, Payment Gateway, ATM

To summarize, If you are planning to become a top class software engineer then you only need to know a few basic concepts of computer science. To learn those you do not need to go through books. All you need to do is solve the problems that I have solved and understand the concept behind the solutions. Once you have solved 100 of these problems you will automatically understand all the necessary concepts. Rest of it can be picked up once you start your job.

  • Open account on leetcode and hackerrank
  • Solve at-least one problem everyday (either an already solved one or a new one)
  • Continue this for 6 months and start applying for your dream job

The industry is always in search for good software developers. I have got a lot of friends in major software companies in India, who are constantly in search of software engineers at all levels of experience. If you can comfortably finish the above process, I would be happy to connect you with potential employers. Feel free to connect with me on linkedin if you have any questions on preparation and application.

--

--