Microsoft Engineer SDE2 Handbook
Microsoft Engineer SDE2 Handbook
- Don't waste time thinking I will read all concepts and then get started, we never get around
to doing it!
- Start with Blind 75, to get a taste of Problem solving once again, start with Easy Problems
and then tackle Mediums later, else you may get demotivated and bye bye switch.
- We will revise concepts as we tackle them : Priority queue, Arrays, Merge Sort, etc.
- Then we will Focus on mastering the high ROI areas for Interviews.
- After that we will focus on some coding Patterns
- Then a deep dive into some more problems that are frequently asked in coding interviews
- And then we will keep doing the daily streak to remain in touch with coding!!
These problems get asked a lot, but there aren't many variations. For example, the linked list
category has several classic problems such as reversing a linked list, finding the middle node
of a linked list, and linked list cycle detection that get asked repeatedly.
Priority queue and heap show up surprisingly more often than most would think. The classic
problems include the median of a data stream, k closest points.
Dynamic programming (DP) is hard to summarise and does not frequently appear (unless you
are interviewing Google, whose engineers like to ask DP problems). There are a few classic
problems you may want to know such as house robber and robot paths. Otherwise, you
should probably focus on higher ROI areas if you are short on time. Also, if you can't figure
out a dynamic programming solution, you can always do DFS + memoization which does the
same thing.
Each greedy problem is different, and it's hard to summarise a pattern, and the correctness of
your solution often requires rigorous mathematical proof that is hard to learn in a short time.
Therefore, we consider the greedy problem to be low ROI.
38 | Pratham Kohli
Pro tip 1: Catch up on STL Libraries of the language you will code in for DSA, seeing this
now will help you get up to speed when you see solutions of other people in the Leetcode
Discuss Section as you solve problems
Pro tip 2: Be very thorough with Time Complexities of Data Structures and your solutions.
Messing up the Time complexity can cost you your interview, even if you did everything
right, including the Implementation of Code.
Pro Tip 3: Don’t Spend more than 40 mins on one question, 1.5 hrs at max if it is Hard ( but
try sticking to the 40-45 mins mark).
Pro Tip 4: Even if you were able to solve the question, check the Leetcode Discuss section
for other possible solutions.
It opens up your mind to solutions you didn’t know existed. You get the Eureka moments!!
You exercise your mind and understand how other people think.
Don’t skip this GOLDMINE!!
Array
● Two Sum
● Best Time to Buy and Sell Stock
● Contains Duplicate
● Product of Array Except Self
● Maximum Subarray
● Maximum Product Subarray
● Find Minimum in Rotated Sorted Array
● Search in Rotated Sorted Array
● 3 Sum
Binary
● Sum of Two Integers
● Number of 1 Bits
● Counting Bits
● Missing Number
● Reverse Bits
Dynamic Programming
● Climbing Stairs
● Coin Change
● Longest Increasing Subsequence
● Longest Common Subsequence
● Word Break Problem
● Combination Sum
● House Robber
● House Robber II
● Decode Ways
● Unique Paths
● Jump Game
Graph
● Clone Graph
● Course Schedule
● Pacific Atlantic Water Flow
● Number of Islands
● Longest Consecutive Sequence
● Alien Dictionary (Leetcode Premium)
● Graph Valid Tree (Leetcode Premium)
● Number of Connected Components in an Undirected Graph (Leetcode Premium)
40 | Pratham Kohli
Interval
● Insert Interval
● Merge Intervals
● Non-overlapping Intervals
● Meeting Rooms (Leetcode Premium)
● Meeting Rooms II (Leetcode Premium)
Linked List
● Reverse a Linked List
● Detect Cycle in a Linked List
● Merge Two Sorted Lists
● Merge K Sorted Lists
● Remove Nth Node From End Of List
● Reorder List
Matrix
● Set Matrix Zeroes
● Spiral Matrix
● Rotate Image
● Word Search
String
● Longest Substring Without Repeating Characters
● Longest Repeating Character Replacement
● Minimum Window Substring
● Valid Anagram
● Group Anagrams
● Valid Parentheses
● Valid Palindrome
● Longest Palindromic Substring
● Palindromic Substrings
● Encode and Decode Strings (Leetcode Premium)
Heap
● Merge K Sorted Lists
● Top K Frequent Elements
● Find Median from Data Stream
42 | Pratham Kohli
20 Coding Patterns to know before your Interviews
( Courtesy: DesignGurus )
Coding patterns enhance our “ability to map a new problem to an already known problem.”
Coding Patterns simply mean multiple problems having similar kind of solutions and which
can be solved in a similar way
1. Sliding Window
Usage: This algorithmic technique is used when we need to handle the input data in a specific
window size.
Sample Problems:
- Longest Substring with 'K' Distinct Characters
- Fruits into Baskets
Usage: This pattern describes all the efficient ways of traversing a matrix (or 2D array).
Sample Problems:
- Number of Islands
- Flood Fill
- Cycle in a Matrix
44 | Pratham Kohli
3. Two Pointers
Usage: This technique uses two pointers to iterate input data. Generally, both pointers move
in the opposite direction at a constant interval.
Sample Problems:
- Squaring a Sorted Array
- Dutch National Flag Problem
- Minimum Window Sort
Sample Problems:
- Middle of the LinkedList
- Happy Number
- Cycle in a Circular Array
Sample Problems:
- Conflicting Appointments
- Minimum Meeting Rooms
6. Cyclic Sort
Usage: Use this technique to solve array problems where the input data lies within a fixed
range.
DS Involved: Array
Sample Problems:
- Find all Missing Numbers
- Find all Duplicate Numbers - Find the First K Missing Positive Numbers
46 | Pratham Kohli
7. In-place Reversal of a LinkedList
Usage: This technique describes an efficient way to reverse the links between a set of nodes
of a LinkedList. Often, the constraint is that we need to do this in-place, i.e., using the
existing node objects and without using extra memory.
DS Involved: Array
Sample Problems:
- Reverse every K-element Sub-list
- Rotate a LinkedList
8. Breadth-First Search
Usage: This technique is used to solve problems involving traversing trees or graphs in a
breadth-first search manner.
Sample Problems:
- Binary Tree Level Order Traversal
- Minimum Depth of a Binary Tree
- Connect Level Order Siblings
Sample Problems:
-Path With Given Sequence
-Count Paths for a Sum
Usage: In many problems, we are given a set of elements that can be divided into two parts.
We are interested in knowing the smallest element in one part and the biggest element in the
other part. As the name suggests, this technique uses a Min-Heap to find the smallest element
and a Max-Heap to find the biggest element.
11. Subsets
Usage: Use this technique when the problem asks to deal with permutations or combinations
of a set of elements.
Sample Problems:
- String Permutations by changing case
- Unique Generalized Abbreviations
DS Involved: Array
Sample Problems:
- Ceiling of a Number
- Bitonic Array Maximum
Usage: This technique uses the XOR operator to manipulate bits to solve problems.
Sample Problems:
- Two Single Numbers
- Flip and Invert an Image
Sample Problems:
- ‘K’ Closest Points to the Origin
- Maximum Distinct Elements
48 | Pratham Kohli
15. K-way Merge
Usage: This technique helps us solve problems that involve a list of sorted arrays.
Sample Problems:
- Kth Smallest Number in M Sorted Lists
- Kth Smallest Number in a Sorted Matrix
Usage: Use this technique to find a linear ordering of elements that have dependencies on
each other.
Sample Problems:
- Tasks Scheduling
- Alien Dictionary
Usage: This technique is used to solve optimization problems. Use this technique to select
elements that give maximum profit from a given set with a limitation on capacity and that
each element can only be picked once.
Sample Problems:
- Equal Subset Sum Partition
- Minimum Subset Sum Difference
Sample Problems:
- Staircase
- House Thief
Sample Problems:
- Longest Palindromic Subsequence
- Minimum Deletions in a String to make it a Palindrome
Sample Problems:
- Maximum Sum Increasing Subsequence
- Edit Distance
50 | Pratham Kohli
More questions and Resources to Master DSA problem and
Patterns from:
Arrays:
1. Top 50 Array Coding Problems for Interviews
2. Solve Array problems from Striver’s sheet
Sliding Window :
1. Sliding Window algorithm template to solve all the Leetcode substring search
problem
2. Sliding window substring problems template
Binary Search:
I love the following doc, this will clear a lot of your Binary Search doubts, on when to take
what limits, how to take mid, when to increase / decrease interval!!
This is explained via a problem statement, do give it a read!!
Problem Statement:
https://leetcode.com/problems/furthest-building-you-can-reach/ :
You are given an integer array heights representing the heights of buildings, some bricks, and
some ladders.
You start your journey from building 0 and move to the next building by possibly using
bricks or ladders.
● If the current building's height is greater than or equal to the next building's height,
you do not need a ladder or bricks.
● If the current building's height is less than the next building's height, you can either
use one ladder or (h[i+1] - h[i]) bricks.
Return the furthest building index (0-indexed) you can reach if you use the given ladders and
bricks optimally.
Example 1:
Output: 4
- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.
- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 <
9.
It is impossible to go beyond building 4 because you do not have any more bricks or ladders.
Example 2:
Output: 7
52 | Pratham Kohli
Example 3:
Output: 3
Constraints:
Solution:
Binary search's details easily confuse many programmers, so many become tempted to resort
to poor practices such as Programming by Permutation. With that in mind, I'm going to walk
you through a methodical way of approaching this problem that also applies to other binary
search problems. If you’re already confident with binary search and don't want to walk
through it in this level of detail, then you can skip straight to the pseudocode, or ideally, go
away and try and code it up on your own. Otherwise, I recommend following really carefully,
as this process really does help.
The importance of being able to methodically design and implement a binary search cannot
be understated. You'll almost certainly encounter it in multiple interviews. Focus firstly on
your accuracy and then work on your coding speed. While coding fast and correctly is the
ideal, keep in mind that accuracy is still worth more than speed. Buggy code is bad, no matter
how quickly you wrote it.
These are the questions we'll be answering and then putting into code.
We want to know which building in the heights array (i.e., not a climb distance) is the
final-reachable-building. Buildings are identified by indexes in the array; therefore, we're
looking for the index in heights that corresponds to the final-reachable-building. It might
The highest possible index for the final-reachable-building is heights.length - 1 (i.e. the last
building in heights). In the worst case, the only building we’ll be able to reach is the building
at index 0 (which we can always reach). Therefore, the answer could be anywhere from 0 to
heights.length - 1, inclusive of both of these endpoints. In the binary search code, this will be:
lo = 0
hi = heights.length - 1
Notice that we haven't used hi = heights.length or lo = -1, or anything else like that. People
are sometimes tempted to put that stuff in to "cover edge cases", handle inclusive vs.
exclusive endpoints, etc., without fully understanding what they were trying to achieve with
it. It's generally easiest to set lo to represent the lowest possible position of the target and hi
to be the highest possible position.
Often in a binary search, we immediately know when we've found the answer. For example,
if the problem was to search for 12 in a sorted array, then as soon as the value at mid is 12,
we can return true.
For this problem, though, we can't do that. If the value of isReachable(mid) is true, then it is
possible that it is indeed the final-reachable-building, but it is also very possible that the
final-reachable-building is further to the right. Because of this, we should instead shrink the
search space down to length-one (i.e., to where lo = hi) and then determine whether or not
that one item is the one we want. In this case, we know that the target definitely exists, so as
soon as the search space is of length-one, the index in it is for the final-reachable-building.
lo = 0
hi = heights.length - 1
while lo is less than hi:
Details here are still to be decided
return lo
Don't attempt to keep track of the highest true so far using an additional variable. It's
unnecessary, as we can simply shrink the search space down so that in the end, it only
contains the final reachable value.
54 | Pratham Kohli
Step 4: What can we conclude when isReachable(mid) returns true?
If isReachable(mid) returns true, then we know that the building at mid is reachable. We're no
longer interested in any of the buildings before mid, as they can’t possibly be the
final-reachable-building (as mid is further than them).
We don't know whether or not the building at mid + 1 is reachable, though, and nor should we
check right now.
Setting lo = mid + 1 would be incorrect here because it’s possible that all buildings from mid
+ 1 onwards are not reachable, and that we’ve just chopped the final-reachable-building out
of the search space (remember, we want to shrink the search space down to a single index;
the index of the final-reachable-building).
If isReachable(mid) returns false, then we know that the building at mid is not reachable.
This means that none of the buildings after mid could possibly be reachable either. Therefore,
the final reachable building must be before mid; in other words, the highest possible
candidate now is mid - 1. So we should set hi = mid - 1.
A common mistake here is to simply use hi = mid so as to avoid having to reason about
whether or not to put the - 1. This is very problematic, though, as whenever you’re doing a
binary search with the while lo is less than hi condition (i.e., reducing the search space to
length-one), you must have at least one of hi = mid - 1 and lo = mid + 1. If you have neither
of these, then your algorithm might infinitely loop once the search space is of length-two.
Updating our code with the latest details we've determined, here is what we have so far.
lo = 0
hi = heights.length - 1
while lo is less than hi:
mid = [formula to be decided]
if building at mid is reachable:
lo = mid
else:
hi = mid - 1
return lo
Your decision should be based on how you are updating hi and lo (i.e., lo = mid and hi = mid
- 1 for the algorithm we've designed here). Think about what happens once the search space
is of length-two. You must ensure that the search space is guaranteed to be shrunk down to
length-one, regardless of which condition is executed. If you take the lower middle, it will
sometimes infinitely loop. And if you take the upper middle, it will be guaranteed to shrink
the search space down to one.
The short rule to remember is: if you used hi = mid - 1, then use the higher midpoint. If you
used lo = mid + 1, then use the lower midpoint. If you used both of these, then you can use
either midpoint. If you didn’t use either (i.e., you have lo = mid and hi = mid), then,
unfortunately, your code is buggy, and you won’t be able to guarantee convergence.
Whenever we want the upper middle, we use either mid = (lo + hi + 1) / 2 or mid = lo + (hi -
lo + 1) / 2. These formulas ensure that on even-lengthed search spaces, the upper middle is
chosen and on odd-lengthed search spaces, the actual middle is chosen.
lo = 0
hi = heights.length - 1
while lo is less than hi:
mid = lo + (hi - lo + 1) / 2
if building at mid is reachable:
lo = mid
else:
hi = mid - 1
return lo
class Solution {
56 | Pratham Kohli
int mid = lo + (hi - lo + 1) / 2;
if (isReachable(mid, heights, bricks, ladders)) {
lo = mid;
} else {
hi = mid - 1;
}
}
return hi; // Note that return lo would be equivalent.
}
private boolean isReachable(int buildingIndex, int[] heights, int bricks, int ladders) {
// Make a list of all the climbs we need to do to reach buildingIndex.
List<Integer> climbs = new ArrayList<>();
for (int i = 0; i < buildingIndex; i++) {
int h1 = heights[i];
int h2 = heights[i + 1];
if (h2 <= h1) {
continue;
}
climbs.add(h2 - h1);
}
Collections.sort(climbs);
// And now determine whether or not all of these climbs can be covered with the
// given bricks and ladders.
for (int climb : climbs) {
// If there are bricks left, use those.
if (climb <= bricks) {
bricks -= climb;
// Otherwise, you'll have to use a ladder.
} else if (ladders >= 1) {
ladders -= 1;
// And if there are no ladders either, we can't reach buildingIndex.
} else {
return false;
}
}
return true;
}
}
Two pointers :
1. General summary of what kind of problem can/ cannot solved by Two Pointers
Recursion:
1. Recursive Practice Problems with Solutions
Backtracking :
1. Backtracking Summary and general template to solve many problems
2. A general approach to backtracking problems in C++
3. A general approach to backtracking problems in Java
4. Backtracking: Practice Problems and Interview Questions
58 | Pratham Kohli
Dynamic Programming :
Suggested Playlist:
or
Questions to Solve:
Bitmasks:
1. Dynamic Programming with Bitmasks
GRAPHS:
Suggested Playlist:
Questions to Solve:
String Manipulation
1. Top 21 String Programming Interview Questions for Beginners and Experienced
Developers
Greedy Algorithms -
1. Top 7 Greedy Algorithm Problems
Segment Trees:
1. Segment Trees
60 | Pratham Kohli
Now what is next ?
Start practising problems everyday
- You can glance over Striver’s sheet once for more questions on Arrays, and other
concepts that are mentioned in the sheet: link
- Do the daily Leetcode streak to keep in touch with problems and test your ability to
tackle any problem ( any pattern ) to see how your brain detects them
- This will come with practice
- Give Contest
- Why ?
- A timed environment is a best replica of your interview, solve contests and try
to do problems as quickly as possible
- This will help in Online Assessments and even in Interviews
- More Resources:
- Grind 75 : [ link ]
- Algo monster: [ link ]
- For the daily problems,
- Keep a timer, give at max 40 mins to questions and then move on to see
discuss sections
- Mark this problem and note it in a list, come back to it after a week, really
necessary as if the same problem comes in interview but you don’t remember
on how to tackle it properly, it can cost you
- Also in revision, these are the problems that we need to go over, the ones we
were not able to do in the 1st attempt. ( as mostly the ones we were able to do
naturally, we should be able to do again if we see something similar)
2. If the given input is a sorted array or a list, we will either be using Binary Search or the
Two Pointers.
3. If we need to try all combinations (or permutations) of the input, we can either use
Backtracking or Breadth First Search.
4. Most of the questions related to Trees or Graphs can be solved either through Breadth First
Search or Depth First Search.
6. For a problem involving arrays, if there exists a solution in O(n^2)time and O(1) space,
there must exist two other solutions: 1) Using a HashMap or a Set for O(n) time and O(n)
space, 2) Using sorting for O(n log n) time and O(1) space.
8. If we need to find some common substring among a set of strings, we will be using a
HashMap or a Trie.
9. If we need to search/manipulate a bunch of strings, Trie will be the best data structure.
10. If the problem is related to a LinkedList and we can't use extra space, then use the Fast &
Slow Pointer approach.
62 | Pratham Kohli
Phase 4 : System Design
[ Low Level Design ]
SOLID design principles represent a set of guidelines that helps us to avoid a bad design
when designing and developing software. The design principles are associated to Robert
Martin who gathered them in "Agile Software Development: Principles, Patterns, and
Practices". According to Robert Martin there are 3 important characteristics of a bad design
that should be avoided:
● Rigidity - It is hard to change because every change affects too many other parts of
the system.
● Fragility - When you make a change, unexpected parts of the system break.
● Immobility - It is hard to reuse in another application because it cannot be
disentangled from the current application.
In this context a responsibility is considered to be one reason to change. This principle states
that if we have 2 reasons to change for a class, we have to split the functionality in two
classes. Each class will handle only one responsibility and on future if we need to make one
change we are going to make it in the class which handle it. When we need to make a change
in a class having more responsibilities the change might affect the other functionality of the
classes.
Single Responsibility Principle was introduced Tom DeMarco in his book Structured
Analysis and Systems Specification, 1979. Robert Martin reinterpreted the concept and
defined the responsibility as a reason to change.
● Software entities like classes, modules and functions should be open for extension but
closed for modifications.
OPC is a generic principle. You can consider it when writing your classes to make sure that
when you need to extend their behavior you don't have to change the class but to extend it.
The same principle can be applied for modules, packages, libraries. If you have a library
containing a set of classes there are many reasons for which you'll prefer to extend it without
changing the code that was already written (backward compatibility, regression testing, ').
This is why we have to make sure our modules follow Open Closed Principle.
When referring to the classes Open Close Principle can be ensured by use of Abstract Classes
and concrete classes for implementing their behavior. This will enforce having Concrete
Classes extending Abstract Classes instead of changing them. Some particular cases of this
are Template Pattern and Strategy Pattern.
This principle is just an extension of the Open Close Principle in terms of behavior meaning
that we must make sure that new derived classes are extending the base classes without
changing their behavior. The new derived classes should be able to replace the base classes
without any change in the code.
64 | Pratham Kohli
Liskov's Substitution Principle was introduced by Barbara Liskov in a 1987 Conference on
Object Oriented Programming Systems Languages and Applications, in Data abstraction and
hierarchy
● Clients should not be forced to depend upon interfaces that they don't use.
This principle teaches us to take care how we write our interfaces. When we write our
interfaces we should take care to add only methods that should be there. If we add methods
that should not be there the classes implementing the interface will have to implement those
methods as well. For example if we create an interface called Worker and add a method lunch
break, all the workers will have to implement it. What if the worker is a robot?
As a conclusion Interfaces containing methods that are not specific to it are called polluted or
fat interfaces. We should avoid them.
● High-level modules should not depend on low-level modules. Both should depend on
abstractions.
● Abstractions should not depend on details. Details should depend on abstractions.
The Dependency Inversion Principle states that we should decouple high level modules from
low level modules, introducing an abstraction layer between the high level classes and low
level classes. Furthermore it inverts the dependency: instead of writing our abstractions based
on details, we should write the details based on abstractions.
Dependency Inversion or Inversion of Control are better known terms referring to the way in
which the dependencies are realised. In the classical way when a software module(class,
framework, ') needs some other module, it initialises and holds a direct reference to it. This
will make the 2 modules tight coupled. In order to decouple them the first module will
provide a hook(a property, parameter, ') and an external module controlling the dependencies
will inject the reference to the second one.
By applying the Dependency Inversion the modules can be easily changed by other modules
just changing the dependency module. Factories and Abstract Factories can be used as
dependency frameworks, but there are specialized frameworks for that, known as Inversion of
Control Container.
Important: Read more about SOLID Principles with Visualisations and examples via this
Medium Blog: link
After establishing are basic pillars of OOPs and SOLID Principles, time to understand some
design patterns.
1. Strategy Pattern
2. Observer Pattern
3. Decorator Pattern
4. Factory Pattern
5. Abstract factory Pattern
6. Singleton Pattern[ Also Read on how to make it thread safe]
7. Adapter Pattern
8. Facade Pattern
9. Chain of Responsibility Pattern
10. Memento Design Pattern
11. Composite Design Pattern
12. State Design Pattern.
66 | Pratham Kohli
Recommended Sources:
1. Head First Design Patterns Book - Either Purchase, or simply download online [ just
do a google search ]
Here are my notes for Revision: link, but recommended to write your own notes as well!
68 | Pratham Kohli
Videos to watch to understand how to approach Problems:
1. How to Approach an LLD Problem (using Hotel Management System example) ? link
2. LLD Code Implementation (using Hotel Management System example) : link
3. Library Management System [ Approach and Use case diagram ] : link
4. Library Management System [ Code ] : link
5. Ticket Booking System [ Movie / Event booking] : link
6. E-commerce website LLD : link
7. ATM LLD : link
8. Chess LLD : link
9. Parking Lot : link
10. Stack Overflow LLD : link
The machine-coding round is a major part of the interview process when you are targeting
startups (or Uber )
This is the same as LLD but now you need to implement a running code, end to end in the
interview or take home assignment.
This is a good manual and provides valuable insights and strategies for acing machine coding
rounds.
Other resources of end to end code are present in the Github Repo above!
Preparation Tips
Solve at least 2 of each type and you should be good. Take following points into
consideration while practising
Learn these
Try to use evergreen design patterns in your solution like - Singleton pattern, factory pattern,
adapter pattern, strategy pattern, chain of responsibility pattern, memento design pattern,
composite design pattern, observer pattern, state design pattern.
70 | Pratham Kohli
● Create service layer
● Identify special design that fits here - strategy design, state design, etc etc.
What else to do ?
3. Peer Discussions ( If possible have a buddy you can practise this with):
Connected with friends for in-depth discussions on code optimization strategies,
debate on the pros and cons of different approaches to improve your problem-solving
skills.
Must Do:
Start with Gaurav Sen’s basic playlist to get familiar with terms: link to the playlist
Terms to become familiar with:
- Horizontal, Vertical Scaling
- Load balancing
- Consistent Hashing
- Message Queue
- Microservice Architecture
- Database Sharding
- Distributed Cache
- What is an API and How to Design it ?
- Capacity Planning and Estimation
- CDNs ( Content Delivery Systems)
- Single Point of Failure
- Event Driven System
- NoSQL Databases
- Database Scaling
- Data Replication, Distributed Consensus
- Cascading Failures
- Cloud Computing
- CAP Theorem
- Data Consistency
- Monoliths vs Microservices
72 | Pratham Kohli
But I would recommend you 1st watch Gaurav Sen’s playlist, then read Alex Xu’s book and
later read the System Design Primer.
1. Database Design Tips | Choosing the Best Database in a System Design Interview :
link
2. Google Maps: link
3. Video Streaming Platform ( Netflix, prime, Hulu) [ Imp ] : link
4. Twitter / Read - Heavy System : link
5. Social Network Design [Facebook / Instagram / Linkedin]: link
6. Cab Booking SYstem [ Uber / Ola ] : link
7. Design E-commerce Application [ Amazon / Flipkart ] : link
8. Design a Chat Application [ Whatsapp / Facebook Messenger ] : link
9. Video Conference Application [ Zoom / Whatsapp Video / Facebook Video Call ] :
link
10. URL Shortening Service : link
11. Hotel Booking System [ Airbnb / Booking.com ] : link
12. Notification Service System [ that is very Scalable] : link
13. System Design Tips and Tricks : link
- More solutions for Design problems can be found in Grokking the Design interview : Free
version pdf can be found easily on internet
74 | Pratham Kohli
After going through the above content, about two to three times, you should have a really
good catch on what to expect and how to think.
If this feels daunting, don’t worry, everybody feels the same.
Practise the above at least two to three times to become fluent in the way you should tackle
the System Design problems
- Alex Xu book vol 2 - This one is advanced and is recommended after all basics and basic
designs are clear.
More Resources if you want to build more knowledge, generally not required unless you are
applying for a Senior role:
1. System Design Interview | Step by Step Guide : link
2. Top K Problems ( heavy Hitters ) : link
3. Distributed Cache: link
4. Rate Limiting : link
5. Notification Service: link
6. Distributed Message Queue: link
- Github Repo with more videos, blogs to tackle more System Design problems: link
[Repo Name: awesome-system-design-resources ]
To build a Deeper Understanding of System Design, not only for Interviews but for you
Career as well, check this:
- Designing Data Intensive applications : Link to purchase
1. If we are dealing with a read-heavy system, it's good to consider using a Cache.
2. If we need low latency in the system, it's good to consider using a Cache & CDN.
3. If we are dealing with a write-heavy system, it's good to use a Message Queue for Async
processing
5. If data is unstructured & doesn't require ACID properties, we should go for NO-SQL
Database
6. If the system has complex data in the form of videos, images, files etc, we should go for
Blob/Object storage
7. If the system requires complex pre-computation like a news feed, we should use a Message
Queue & Cache
8. If the system requires searching data in high volume, we should consider using a search
index, tries or a search engine like Elasticsearch
9. If the system requires to Scale SQL Database, we should consider using Database Sharding
10. If the system requires High Availability, Performance, & Throughput, we should consider
using a Load Balancer
11. If the system requires faster data delivery globally, reliability, high availability, &
performance, we should consider using a CDN
12. If the system has data with nodes, edges, and relationships like friend lists, & road
connections, we should consider using a Graph Database
13. If the system needs scaling of various components like servers, databases, etc, we should
consider using Horizontal Scaling
14. If the system requires high-performing database queries, we should use Database Indexes
15. If the system requires bulk job processing, we should consider using Batch Processing &
Message Queues
76 | Pratham Kohli
16. If the system requires reducing server load and preventing DOS attacks, we should use a
Rate Limiter
17. If the system has microservices, we should consider using an API Gateway
(Authentication, SSL Termination, Routing etc)
18. If the system has a single point of failure, we should implement Redundancy in that
component
19. If the system needs to be fault-tolerant, & durable, we should implement Data Replication
(creating multiple copies of data on different servers)
20. If the system needs user-to-user communication (bi-directional) in a fast way, we should
use Websockets
21. If the system needs the ability to detect failures in a distributed system, we should
implement a Heartbeat
22. If the system needs to ensure data integrity, we should use Checksum Algorithm
23. If the system needs to transfer data between various servers in a decentralised way, we
should go for the Gossip Protocol
24. If the system needs to scale servers with add/removal of nodes efficiently, with no
hotspots, we should implement Consistent Hashing
25. If the system needs anything to deal with a location like maps, nearby resources, we
should consider using Quadtree, Geohash, etc
Create a similar sticky note and paste it on your desk or wherever you sit and code day in and
day out!!
78 | Pratham Kohli
Detailed Breakdown:
Recursion &
n ≤ 12 O(n!) Permutation 1….n
Backtracking
Recursion ,
All subsets of an
n ≤ 25 O(2n) Backtracking & Bit
array of size n
Manipulation
Dynamic
n ≤ 100 O(n4) 4Sum
Programming
Bubble Sort
Dynamic
(Slow
n ≤ 104 O(n2) Programming,
comparison-based
Graphs, Trees
sorting)
Mathematical,
n > 108 O(log n) or O(1) Binary Search
Greedy
80 | Pratham Kohli
Phase 7 - Behavioural Questions
Behavioural Questions and How to Answer Them:
Here is a list of tricky behavioural questions and sensible answers for the same.
The reality is - in such rounds, it is important to sound diplomatic and politically correct.
Yes, it might sound like faking at times, but that is precisely what is needed.
As candidates, we definitely need to appear diplomatic and mature - specially for senior
positions (say 5+ years of experience). In these rounds, these soft skills matter way more than
your stellar coding rounds or design rounds.
0. The MOST IMPORTANT POINT - Resume DrillDown - Know your resume inside out.
Each and every word written in your resume can be questioned, it can be about your technical
skills, it can be about your hobbies or some award won by you. Be very very sure about
everything which you have written in your resume.
Even a HR person may ask questions about some fancy technical term(s) mentioned in your
skill set. You need to be ready to explain technical terms at a high level in 2-3 sentences. And
do not under-estimate the HR - I have personally known people working in HR who have a
background in Computer Science, and they are equally capable to grill you technically as
well.
Always frame the answer around things like - not learning anything new as the product is in a
saturated state, and unable to switch teams due to internal policies.
NEVER EVER talk about bad boss, politics etc - it will backfire bigtime.
We can also talk about your interest in the technology on which the company (who is
interviewing you) is working on.
In case your current company is recently acquired by another bigger company, then you can
always talk diplomatically about uncertainty in the environment in your company, several key
people leaving after acquisition, product being discontinued or put in maintenance mode etc.
This is a similar question to the first one. Only difference is - for this question - we need to be
able to talk about 1-2 core products created by that company, the tech stack, and being able to
express our interest in the same. A sample answer maybe - I came to know about your
company because of product X, and I found it a very interesting concept.
Expressing interest in their technology is 50% job done for behavioural interviews.
MOST IMPORTANT PART - you must SOUND genuinely passionate when answering this
question. Practise rehearsing your lines in front of a mirror for this question - it may help.
3. What has been the biggest failure of your career till now ?
OR
What is the most critical feedback received from your boss in your entire career ?
Even if there is no such thing in reality (for people with say less than 3 years of experience),
do craft a reasonable story.
Talk about a time when you caused a major feature break, or a serious bug missed by you
which came through customer etc.
You can add that it caused a lot of chaos and I received very critical feedback from my boss
saying - "I did not expect this mistake from you".
Then talk about some corrective actions which you took, like enhancing test automation, or
getting into TDD mode etc and this helped in minimising future recurrences of such nature.
YES, talking about corrective actions is the most important part here.
If possible, support with data like - this enhancement in our process helped in preventing at
least 20 show stopper bugs from slipping in.
Talk about your routine like - we have daily status meetings as first thing in the morning, then
we get onto development/debugging work, customer calls etc. Try to compress in 3-4
sentences at max.
Again, SOUND passionate and energetic when answering this question.
Here the interviewer may ask a follow-up question - what do you do in your free time at
work?
Possible answer - I prefer to read about other components of the product on which I have not
worked, and try to understand how to debug/troubleshoot those pieces of code.
Or else - my company has a huge repository of learning resources - I try to learn new things
etc
82 | Pratham Kohli
In case you are more on the management side, then be prepared to justify how you keep your
technical skills up-to-date.
Again a trap - if you badmouth your current employer or use any words like hate or dislike, it
is guaranteed to go against you.
Talk about generic things like - sometimes code reviews take a long time due to senior
developers being busy - probably that can be streamlined.
Or say - we should invest more in enhancing the test automation infrastructure, which often
takes a backseat due to various constraints
Basically, try to stay around technical things, and avoid talking about poor cafeteria or no free
cab pickup-drop services etc.
The motive is to show your passion towards work related things and not focus on secondary
things like cafeteria or cabs or playgrounds etc.
So, answer it diplomatically around point 1 of this post. Talk about good things like - I have
gotten to learn a lot.
If by any chance your current job is your first job - then definitely talk about things like - I
learnt the ways of working in industry in this job and hence this job will always be special for
me etc etc.
Then talk about negatives - again in a polished way - now the product has really evolved and
hence there is not much productive work to do other than customer support or maintenance
etc. Or else say that I have worked for a really long time on the same technology stack, and
want to expand my breadth by getting a chance to work on other technologies.
You may also borrow a few points listed in "Why do you want to quit your current job" above
in this post.
This one is a make-or-break cultural fit question. Always answer diplomatically saying that
age/years etc are irrelevant for me. What matters for me is what can I learn from someone
irrespective of whether that person is junior or senior to me. I can learn a few things from my
boss for sure, and if it turns out that I am more experienced or older than my boss, then I am
sure I can be a valuable resource for my boss in terms of helping out with critical decision
making.
My experience will definitely be an asset for my boss in such cases.
Throw in examples of successful sports team of any sport which you like, there will be
several examples where the captain of a successful sports team is younger than a senior
important veteran player of the team. If you can give that type of analogy, your answer will
sound more genuine/natural.
9. What would you do if you find your senior or boss doing something unethical or
violating a company policy ?
Always talk about that you would gently point out to that person directly, and request that
person to follow the correct process. In case the violations continue, then I would like to
know about the violation reporting policy of your company.
Here, you can turn the interview around by cross-questioning your interviewer - "by the way,
can you give a brief insight into the policy violation reporting mechanism which exists in this
company ?"
Talk about any boss who was a strong decision maker, always stood by the team, and openly
praised contributions by team members, and also clearly guided the team members towards
career growth.
Yes, such bosses are very rare in real life - but even if you did not have one such boss in your
real life, do talk along these lines.
Nobody is going to conduct an enquiry about whether you really had a boss who had all these
qualities or not.
Just be careful - not to take any person's name while talking about these qualities. If explicitly
asked, just politely say that I want to respect the privacy of that person, hence won't take any
names.
You can talk like - "Yes, I have been very fortunate to work under one/two such boss(es)
earlier in my career. I learnt a lot from him/her/them. I always found that person to be always
supportive of the team, and that person was the only person who actually told me the
difference between a Software Engineer and a Senior Software Engineer in clear measurable
terms etc etc."
84 | Pratham Kohli
11. Describe the worst boss you have ever worked under.
NEVER NEVER EVER start describing that one bad boss you may have encountered. Be
very very diplomatic here.
One slip of tongue in answering this one - and you are already rejected as "being a poor
culture fit".
You can say something like this and create a reasonable story like this - "Well, nobody is
perfect - everyone is good in some things and not so good in other things. Regarding my
bosses, I am not able to think of anyone who can be labelled as worst as such. I learnt
something or other from each and every boss I worked under.
If I have to explicitly describe the shortcomings of any particular boss, then I will not exactly
call it a shortcoming, but I feel it was his extradordinary passion towards his work. I had a
boss who often used to get so carried away in work when working with us in
brainstorming/discussion sessions that we would often end up getting very delayed for lunch.
Initially I found it irritating, but with the passage of time, I realised that he was a person of
extreme dedication and passion towards his work. The more I worked with him, the more I
learnt from him.
And coming to this lunch time issue, I hesitatingly brought up this point once with him
privately, and he happily agreed to have working lunch in such cases.
So, in a nutshell - there are no bad bosses - it is just that their way of working/thinking is
drastically different from ours."
Prepare 2-3 stories of this type, just in case the interviewer adds a follow-up like - "any other
irritating bosses you worked under".
So, the whole idea is to mould a highly negative conversation towards a positive direction.
12. If you have 5+ years experience and mention that you yourself are an interviewer -
then you may be asked to describe your strategy of taking interviews - stuff like what
type of questions you ask, and what are you trying to judge based on that question.
In such a case, be ready with 2-3 questions and present them as your pet questions.
Be ready with justification like - by asking this tricky coding problem, I try to judge up to
what extent the candidate can think, can the candidate come up with different approaches etc.
By asking this question Y - I try to get a feel as to whether the candidate will be a decent
cultural fit in our company or not.
Be prepared for a follow-up like - "if you have to look at your own interview rounds going on
right now in this company, what do you think the interviewers were trying to judge about
you."
Try to answer on similar lines staying close to job description. You can say - "as this job is for
a Senior Software Engineer, so it is expected that the interviewer would like to be fully
convinced about my coding abilities. So, it is quite natural that I was asked X, Y, Z. In the
current round, I believe you are trying to take a call as to whether people would like to work
Talk about something more genuine and possibly not related to work - I am not so good at
remembering road directions, or maybe people whose first/second language is not English
may feel that occasionally I speak too fast.
But be prepared to answer - what are you doing to overcome this weakness ?
Possible answers to above examples may be - I am trying to get better at remembering road
directions by observing the landmarks more closely when I pass through any road
or
I consciously try to speak at a slower pace and in a neutral accent when interacting with
people whose first/second language may not be English. I am actually trying to learn more
about different cultures across the globe to be sensitive to their requirements.
If you talk about culture, be prepared to talk about a few interesting facts about the culture of
a few countries - e.g. using your left hand to give/take something in Asian countries may be
considered offensive, tipping is not considered good in some countries but is a natural
expectation in some other countries etc.
Being culturally sensitive is very very important for working in any MNC.
Again a cliche question. Just talk about your passion for the role, talk about how your skills
are a perfect match for this role, definitely do highlight any not-so-common achievement of
yours (may be you have been a state level player, or maybe you appeared on a TV show - use
it to market your people skills, maybe you won multiple scholarships in your career).
And at the end say - I strongly believe these qualities of mine make me a worthy candidate
for this role.
Mark the wording - worthy - NOT perfect. Be very cautious as to NOT to sound arrogant.
15. [For fresh graduates/postgraduates only] What is your favourite subject and why ?
Be prepared with 2-3 names, because sometimes the interviewer may dig like - second
favourite subject ?
It is up to you whether you want to stay with routine subjects like Algorithms, Data
Structures etc or choose something else like Machine Learning, AI, Computer Graphics,
Computer Networks.
To answer the why part, NEVER EVER say things like because I always score good
86 | Pratham Kohli
grades/marks in this subject. You must be able to give a solid justification about the real
world applicability of the concepts taught in those subjects.
Some examples maybe - Data structures is the basic foundation of any software which we use
in real life.
Or
Machine learning is the basic concept behind so many useful features like recommended
news, purchase suggestions on e-commerce sites etc
Or
Computer Graphics is the very reason we get to see such amazing 3D/4D movies like <name
any of your favourite 3D/4D movies>
Also, a word of caution here - maybe you studied a subject named Advanced Algorithms or
say Advanced Concepts in Computer Networks - AVOID the word advanced if you can.
Because, using the word advanced may open up a pandora box and you may get bombarded
with several questions about concepts which you may not even have heard of !!
16. [For fresh graduates/postgraduates only] Which subject(s) do you HATE and why ?
This one is a very tricky question to answer, and you need a solid justification for the
same.
You should NEVER use the word HATE but say something like I am not very much
interested in this subject X.
X can be some compulsory elective course which is not exactly related to Computer Science
but is a part of your college/university curricullum. You can justify by saying that I have tried
very hard to understand where would I need to apply the concept taught in that subject, in the
field of software engineering.
By any chance, if your least favorite subject is related to Computer Science, then the only
possible way to justify it could be - I have never gotten any chance to practically apply the
concepts taught in that subject. There are indeed some subjects which are taught only
theoretically - if that is the case then you can give this justification.
Or even better - you can also say that there is no subject which I would put in the category of
dislike/hate, because every subject has its own importance.
17. [For fresh graduates/postgraduates only] Tell me about your major/degree project.
Be prepared to explain each and everything in thorough detail.
Try to structure your answer like this
Motive - what inspired you to take up this project? Justify with some real world application -
max 2-3 sentences
Initial exploration - what all did you read up about it - max 2-3 sentences
Implementation details - preferably a flow/block diagram (if possible), and 5-6 sentence
summary explanation
88 | Pratham Kohli
get more organised as a team, and overall our department sales are up 25% year over
year.”
Disclaimer: All the questions and LPs below are from the Leetcode post: link
[ Nothing is internal, all this was available before I joined any MAANG company. ]
Following is a short and concise (I know even this is long...) list of potential behavioural
Leadership Principles (LPs). SDEs can avoid the last 3 LPs.
Customer Obsession: Start with the customer and work backwards — leaders obsess over
customers
Insists on Highest Standards: Have relentlessly high standards and continuously raise the
bar/drive others to do the same
● A time you were unsatisfied with the status quo. How would you change it?
● Describe the most significant improvement project you’ve lead
● How do you seek out feedback on performance?
Delivers Results: Focus on key inputs and deliver with high quality in a timely fashion
● A time you were driving toward a goal and realised more than half way in that it may
not be the best goal
● A goal you set that took a long time to achieve/are still working towards
● A time you delivered a project under a tight deadline
Bias for Action: Speed is crucial at Amazon — value calculated risk taking
● A time where you’ve taken a calculated risk where speed was crucial
● A time you made an important decision without consulting your manager
● A time where you were able to remove serious roadblocks preventing progress
Invent and Simplify: Expect and require innovation from yourself and those around you —
always find ways to simplify
● The most innovative thing you’ve done and why you think it’s innovative
● A time where you solved a complex problem with a simple solution
● A creative idea you had that ended up being difficult to implement
Dive Deep: Stay connected to details, audit frequently, and question when metrics differ
● A time you were trying to understand a problem on your team and had to go down
several layers to figure it out
● A time you linked two or more problems together an identified an underlying issue
● A specific metric you have used to identify a need for a change in your department
Learn and be Curious: Always seeking improvement — curious about new possibilities
● A time you realised you needed to have a deeper level of subject matter expertise to
do your job well and love to explore them
● A time you took on work outside of your comfort area and found it rewarding
● A time you didn’t know what to do next or how to solve a challenging problem
Disagree and Commit: Obligation to respectfully challenge decisions when you disagree,
then fully committing
Earn Trust: Listen attentively, speak candidly, and treat others respectfully
Think Big: Thinking small is a self- fulfilling prophecy. Leaders create and communicate a
bold directions that inspires results
Hire & Develop The Best: Raise the performance bar with every hire & promotion.
Recognize talent, and willingness to move them throughout the organisation
90 | Pratham Kohli
● A time when you provided feedback to develop & leverage the strengths of someone
on your team.
Frugality: A time when you thought about saving a cost for your team
● A time when you implemented a mechanism that saved money for your business
● A time when you spotted something in the business was wasting money
● A time you made a difficult decision and how you knew it was the right decision.
● A time you made a decision without data
● A time you made a bad decision and how you learned from it
3. One more strategy is to go ahead with real life interviews at real companies
- Start applying to companies you know you are not going to join
- Nothing beats the thrill of a real time interview
- Helps you assess where you are in your prep journey and gives you the required practice
and points to improve on
92 | Pratham Kohli
General Guidelines for All Interviews:
1. Have a good sleep the night before, it helps I am telling you with experience.
2. Join the meeting 5 mins prior always, so that you become familiar with the
environment you are in. It helps keep you calm
3. Always have your charger connected to the laptop and close to a power source, just in
case the battery runs out or becomes low, plug it in.
4. Keep your phone close to you to use hotspot in case your Wifi betrays you in the
interview.
5. Before starting the interview, provide your number in the Zoom chat, in case you
think the internet may go down or the call may disconnect for any reason.
6. Breathing exercises before the interview helps if you are feeling too stressed or
anxious.
7. Most interviewers want you to succeed.
8. Go with a winning mindset and be confident of your abilities.
9. Keep a crisp introduction ready as most interviewers tend to ask you to introduce
yourself.
10. Always start the conversation with a Smile ( seems basic but everybody likes a
cheerful person, don’t you like it when a stranger smiles at you ? [Not in the weird
way though :p ] )
11. Understanding the problem well is the first step during interviews.
12. Never jump straight to the solution.
13. Record any unique information present in the problem. ( write it down on the screen
which is mutually shared)
14. Write down 2-3 test cases to understand the input/output.
15. Never assume things which are not given in the problem.
16. Whatever problem you get, start from basic principles, always tell the brute force
approach first to the interviewer. Explain it quickly as that does not take more than 5
mins generally.
17. Then start providing the optimised solution. [ Solution first. Optimizations later. ]
18. Why brute force soln first ?
- In case you can’t think the optimised solution, it gives you a lead to see what code
blocks can be optimised,
- It lets the interviewer know that you know at least one solution, instead of
interviewer thinking that why are you not able to provide even the basic solution to a
basic problem
19. Always keep speaking what you are thinking, it keeps the interviewer involved and
gives them data points into how you think.
20. If stuck, iterate over all Data structures you know: Stack ? Queue ? Heap? Linked List
? Graph ? to see what soln may work.
21. Listen carefully to the interviewer for hints/suggestions.
- The interviewer may have a solution in mind and sometimes they would want you to
implement that solution only. So be all ears on whatever the interviewer says!
22. It’s ok to use pen and paper and take notes during the interview.
94 | Pratham Kohli
Why should you Ask Questions at the end of An Interview?
- Always ask a question, never ever say no questions
- It matters in some companies, in some it does not
- But it always creates an impression on the interviewer, showing how interested /
uninterested you are in joining them
- You always need to showcase that you are extremely interested in the company even
if you are not
- Instahyre: People get a lot of leads from here as well. Creating a profile is pretty
simple.
Link to Instahyre
- Indeed: This is another platform we can explore but it is not very good at the moment
for India, so I used it only to apply directly to the company Indeed!
Link to Indeed
98 | Pratham Kohli