How to Prepare for and Crack the Coding Interview
How to prepare for the coding interview? And How to crack the coding interview? A lot of people have these questions in the software industry nowadays. And if you are here, you are also probably trying to figure out the answers to these questions. This article will guide you through the process of preparing for the coding interview. And also to crack the coding interview. So it’s a bit easier for you during the interview.
Coding Platform To Prepare For The Coding Interview
If you want to practice for the coding interview, you need a coding platform online. Why? First, to find different problems. And second, you can also solve them on the platform and check the accuracy of your solutions. You can refer to Best Coding Platform To Become A Coding Expert for information about different coding platforms. The article lists the different features of the coding platforms available. And it also lists the pros and cons of each platform. You can select the best platform as per your preferences.
After you have selected the coding platform as per your needs, you need to prepare the coding questions for the interview.
Practice For The Coding Interview
The first step involved to crack the coding interview is preparing for the interview. Because if you want to crack the coding interview, you need to practice. How many coding problems do you need to practice? Well, the short answer is as much as you can. The long answer is it depends on where you are in the preparation stage. If you have been practicing from time to time, you might need to practice approximately 100 problems. Whereas if you are starting from scratch, you might need to practice anywhere between 200 to 300 questions in total. Again, these are just estimates. Actual numbers may vary from person to person.
We have also mentioned some of the important questions for each topic. The names of the companies the respective question was asked are included in brackets.
Also check: How to crack technical interview – Google, Amazon & more
Start With the Basics
The very first thing that you should do to crack the coding interviews is to focus on the basics. Why? Because there’s no point in jumping to problem solving directly if your basics of coding are not up to the mark. And what are the basics of programming? Data Structures and Algorithm. So, let’s first focus on data structures and algorithms.
Data Structures To Prepare For The Coding Interview
First, let’s see the important data structures you need to study to prepare for the coding interview.
The most basic data structure in any programming language is arrays. It is a linear data structure. Contiguous memory locations are used to store the data. It stores similar or homogenous elements only. For random access, you can use an index. The index starts with 0 in most modern programming languages.
- Two Sum (Google, Amazon, Facebook)
- Minimal Tree (Google, Microsoft, Amazon, Adobe)
- 3Sum (Amazon, Microsoft, Facebook)
- Permutations (Google, Facebook, Apple)
It is a linear data structure that follows the LIFO(Last In First Out) principle. The first element to be inserted will be the last element to be removed. It contains only one pointer, top, which points to the topmost element in the stack. Elements can be added or removed only from one place, the top. And top is the only element that can be accessed. Method calls in Java are stored in stacks, one on top of the other.
- Stack – This playlist starts with the basics of Stack, and proceeds to cover a lot of different problems based on Stack.
- Palindrome Linked List (Oracle, Microsoft, Apple)
- Min Stack (Google, Microsoft, Amazon)
- Dinner Plate Stacks (Amazon, Facebook)
- Implement Queue using Stacks (Google, Microsoft, Amazon)
- Max Stack (Google, Amazon, Uber)
It is a linear data structure that follows the FIFO(First In First Out) principle. The first element to be inserted will be the first element to be removed. Elements are inserted from the rear. And deletions are done from the front. Job sequencing, CPU scheduling, Disk Scheduling, etc. are some of the applications of queues.
- Binary Tree Level Order Traversal (Facebook, Microsoft, Adobe)
- Diagonal Sum (Microsoft, Amazon, Samsung)
- Maximum Level Sum of a Binary Tree (Thoughtworks, MAQ Software)
- Implement Stack using Queues (Intuit)
4. Linked List
It is a linear data structure in which data is stored at random memory locations as per availability. It is dynamic in size so the size can grow or shrink as per the need. Insertion and deletion operations are easy as only one link needs to be changed. Unlike arrays, random access is not possible. This is why you must traverse in a linear fashion. So, it is better suited for applications where the size needs constant changes.
- Add Two Numbers (Google, Microsoft, Facebook)
- Palindrome Linked List (Microsoft, Amazon, Facebook, Apple)
- Remove Duplicates from Sorted List (Amazon, Apple, Goldman Sachs)
- Partition List (Microsoft, Amazon, Facebook, Apple)
- Next Greater Node In Linked List (Uber, Facebook, Apple)
5. Binary Tree
It is a hierarchical data structure with the topmost element as the root. Each node has three fields, namely 2 pointers to the left and right children and a data element. Each node can have a maximum of 2 children. Binary Search Tree, Red-Black Tree, AVL Tree are all derivations of Binary Tree.
- Rat In A Maze (Amazon, VISA, Flipkart)
- Right View (Uber, Apple, Amazon)
- Serialize and Deserialize Binary Tree (Uber, Apple, Flipkart)
- Lowest Common Ancestor of a Binary Tree (Google, VISA, Facebook)
6. Binary Search Tree
It is a natural extension of the Binary Tree data structure. The left subtree of a node only contains nodes with keys lower than the node’s key. The right subtree of a node only contains nodes with keys greater than the node’s key. The left and right subtree each must also be binary search trees.
- Minimal Tree (Google, Amazon, Microsoft, Facebook)
- Lowest Common Ancestor of a Binary Search Tree (Microsoft, Amazon, Samsung)
- Binary Search Tree Iterator (Facebook, HSBC, VISA)
- Validate Binary Search Tree (Amazon, Facebook)
A heap is a complete binary tree. There are two types of heap, namely min-heap and max-heap. Heaps forms the basis of the Heap Sort algorithm. Priority Queues also use heap internally to maintain the data. It is mostly used to retrieve the maximum or the minimum element in the data set at any point in time.
- Heap – This playlist starts off with the basics of Heap. And goes on to cover a lot of important problems based on Heap. The playlist also covers some of the problems mentioned below with the solutions.
- Heap, Heap Sort, & Heapify – This video explains what a heap is, what heap sort is, and finally explains the Heapify process in detail.
- Kth Largest Element in an Array (Facebook, Alibaba)
- Merge k Sorted Lists (Microsoft, OLA, eBay)
- Find Median from Data Stream (Google, Facebook, Apple, Samsung)
- Connect Ropes (Amazon, Goldman Sachs)
A graph is a non-linear data structure. It consists of nodes and edges. Edges are lines that connect two nodes in the graph. Graphs can be directed or undirected. They can also be connected or disjoint. Which makes it suitable for a telephone network or a circuit network. It can be used to represent relationships on social networks like Facebook, LinkedIn, etc.
- Graph – This playlist cover graph basics in detail. Then goes on to cover different graph traversal techniques like BFS & DFS.
- Topological Sort (Google, Microsoft, Flipkart, Amazon)
- Jumping Numbers (Oracle, Google, Microsoft, Amazon)
- Clone Graph (Uber, Facebook, Google, Apple)
- Critical Connections in a Network (Amazon, Facebook, Adobe)
- Course Schedule (Google, Apple, Goldman Sachs)
Tries are sometimes known as prefix trees or digital trees. Trie is an excerpt from the word “reTRIEval”. It is an efficient information retrieval data structure. Tries are extensively used in search engines, data analytics, etc. Why? Because it can store the characters of all the words in a sentence in the nodes of the Trie.
- Word Break (Walmart Labs, Oracle, Yahoo, Snapchat, Salesforce)
- Word Break II (Amazon, Dropbox, Uber, Oracle)
- Implement Trie (Prefix Tree) (eBay, Facebook, Google, Amazon)
- Word Search II (Microsoft, Google, Uber, Bloomberg)
- Top K Frequent Words (Uber, Salesforce, LinkedIn, Microsoft)
Also check: Digital Wallet Design – Machine Coding Round Solution
Other Important Topics To Prepare For The Coding Interview
There are some important topics that don’t fall under the traditional data structures umbrella. But they are very important from a coding interview point of view. Let’s look at some of the other important topics to prepare to crack the coding interview.
Strings are very important in the software engineering world. It is an object that represents a sequence of char values. And all modern programming languages use strings in some form or the other. Strings can be a combination of characters, numbers, special characters, etc.
- Valid Parentheses (Intuit, eBay, Bloomberg, IBM, Google)
- Longest Substring Without Repeating Characters (Amazon, Oracle, PayPal, Walmart Labs, Yahoo)
- Longest Palindromic Substring (Airbnb, Mathworks, VMware, Uber)
- Zigzag Conversion (Google, Facebook, Apple, Amazon)
- Regular Expression Matching (Uber, Oracle, Adobe, Microsoft)
It is a technique of mapping a huge amount of data in a data set(table). A hashing function is used for this purpose. Hashing allows data updation and retrieval in constant(1) time. There is a possibility that two values map to the same address. Collision resolution techniques can be used to solve this problem. And linear probing and double hashing are some of the techniques to resolve hash collisions.
- Repeated DNA Sequences (Amazon, LinkedIn, Google)
- Design HashMap (Apple, Goldman Sachs, Uber, Oracle)
- Shortest Palindrome (Facebook, Microsoft, Amazon, Bloomberg)
- Encode and Decode TinyURL (Bloomberg, Google, Oracle, Uber)
- Longest Happy Prefix (Google, Walmart Labs)
Data is the most important part of any application. But there can be terabytes, petabytes, or even zettabytes of data. How to find the data useful to you? Searching comes into the picture here. There are different searching algorithms like linear search and binary search. Linear search can be used on any data set. However, it is time-consuming. In contrast, binary search is a faster algorithm but can work only on sorted data set. We’ll look into binary search in detail in the next section.
- Search Insert Position (SAP, Microsoft, Amazon, Google)
- Sqrt(x) (LinkedIn, Uber, Apple, Facebook)
- First Bad Version (Google, Mocrosoft, Bloomberg, Adobe)
- Intersection of Two Arrays (Indeed, LinkedIn, Oracle, Lyft)
Sorting is the process of arranging the data in an orderly fashion. There are a lot of sorting algorithms and all these algorithms have their own pros and cons. Some of the popular sorting algorithms are Bubble Sort, Insertion Sort, Merge Sort, Quick Sort, and Selection Sort. You can use a custom Comparator in the sort method if you want to provide your own implementation.
- 3Sum (IBM, Mathworks, PayPal, Freshworks, Microsoft, VISA, Uber, Walmart Labs)
- Sort Colors (Google, Amazon, eBay, LinkedIn, Oracle, PayPal)
- 4Sum (Yahoo, Bloomberg, Facebook)
- Merge Intervals (VMware, Walmart Labs, Atlassian, Twitter, Cisco)
- Find Median from Data Stream (Netflix, Facebook, Uber, Twitter, Snapchat)
Important Algorithms To Prepare For The Coding Interview
Let’s jump on to algorithms now. Some of the important algorithms you need to prepare to crack the coding interview are:
Backtracking is a problem solving algorithm, which uses recursion at its core. It involves trying to build a solution incrementally piece by piece. And the solutions that don’t satisfy the conditions are removed during the course of program execution. It uses a brute force approach while trying to find a solution to the problem. Basically, all the possible combinations and solutions are tried. And those solutions that don’t fulfill the criteria are removed or rejected.
If you want to know more about the backtracking algorithm, please refer to the article Backtracking Algorithm Explained With Examples.
- Backtracking Algorithm Explained With Examples – It has all there is to know about the backtracking algorithm. It also contains a few examples so that you are able to understand the concepts better.
- Backtracking – The basics of backtracking are initially explained in the playlist. It then goes on to explain how to use backtracking to solve some important problems on backtracking. Some of the problems below are covered in the playlist too.
- N Queens (Google, Amazon, Facebook, Microsoft, Oracle, Uber)
- Valid Sudoku (Google, Microsoft, Uber, Amazon)
- Letter Combinations of a Phone Number (Nutanix, Amazon, Airbnb, Morgan Stanley, Lyft, Oracle)
- Generate Parentheses (Google, Facebook, SAP, Uber)
- Sudoku Solver (Amazon, Adobe, Expedia, Snapchat)
- Permutations (Microsoft, LinkedIn, PayPal, Walmart Labs, VMware)
2. Divide & Conquer
As the name suggests, this algorithm divides the data set and conquers(arrives at the solution). The essential steps in the divide and conquer algorithm are dividing, conquering, and combining. In the end, we combine the solutions of the subproblems to arrive at the final solution. A lot of algorithms use the divide and conquer technique. Some examples are Quick Sort, Merge Sort, Strassen’s Algorithm, etc. Recursion is used as an integral part of the divide and conquer algorithm.
- Divide & Conquer – This video covers the basics of the divide & conquer algorithm.
- Majority Element (Amazon, Snapchat, Twitter, Yahoo, Adobe)
- Maximum Subarray (Google, Microsoft, LinkedIn, SAP, Atlassian)
- Convert Sorted Array to Binary Search Tree (Apple, Oracle, Airbnb, Bloomberg)
- Median of Two Sorted Arrays (Amazon, Goldman Sachs, VMware, Walmart Labs)
- Sort List (Google, VMware, Facebook, Microsoft)
3. Branch & Bound
Branch & Bound is a problem solving algorithm, similar to backtracking. It is generally used to solve optimization and minimization problems. A state-space tree is used to visualize and solve branch & bound problems. The branch & bound algorithm gets to the solution by exploring all the possible solutions. And then select the best solution as per the criteria.
- Branch & Bound – This playlist covers the basics of branch & bound technique and goes on to explain how to solve some important questions using this method.
4. Binary Search
Binary search is a searching algorithm used on a sorted data set. The data needs to be sorted in ascending or descending order for the binary search algorithm to work correctly. It finds the result by dividing the data set in half repeatedly until the solution is found. Or there can be no further divisions. There are iterative and recursive approaches to binary search.
- Binary Search – This playlist contains the introduction of binary search. Then goes to cover a lot of problems. Some of the problems below are covered too alongwith the solutions.
- Search Insert Position (Google, Amazon, Microsoft, Apple, SAP)
- Search in Rotated Sorted Array (Adobe, Cisco, Goldman Sachs, Nutanix, Tesla)
- Find First and Last Position of Element in Sorted Array (Facebook, Bloomberg, Uber, VISA)
- Search a 2D Matrix (Google, Amazon, Apple, Microsoft, Uber)
- Median of Two Sorted Arrays (eBay, Airbnb, Yahoo, Walmart Labs)
Recursion is the process by which a method calls itself directly or indirectly. It is suitable in situations where repetition is involved. Recursion is time-consuming and slow and also consumes a lot of stack space. Because of this, it is mostly avoided in real-world scenarios. Suppose a recursive call is made on data set A. So the next recursive call will be made for data sets B & C, where B & C are smaller subsets of A.
- Recursion – This playlist starts off with basics of recursion. And how it can be used in day-to-day programming. It also covers a lot of problems on recursion and also the solutions.
- Merge Two Sorted Lists (Google, Adobe, Airbnb, Oracle, Walmart Labs)
- Add Two Numbers (Microsoft, PayPal, Oracle, Mathworks, Yahoo)
- Swap Nodes in Pairs (Amazon, Apple, SAP, Lyft, Uber)
- Reorder List (Google, Microsoft, Facebook, Cisco)
- Wildcard Matching (Google, Microsoft, Amazon, Facebook, Goldman Sachs)
6. Dynamic Programming
Dynamic programming is recursion + some amount of optimization. So make sure your recursion concepts are clear before starting off with dynamic programming. It is used to solve problems that have overlapping subproblems and optimal substructure properties. If a problem can be divided into subproblems, which in turn can also be further divided into subproblems and there is some amount of overlap between these subproblems, we can store results of subproblems for future usage. There are two dynamic programming approaches, namely the top-down approach, and the bottom-up approach.
- Dynamic Programming – This playlist is inarguably one of the best playlist there is for dynamic programming. It covers dynamic programming in great detail and also explains the different types of dynamic programming. And this playlist also covers 40+ problems based on dynamic programming along with their solutions.
- Maximum Subarray (Google, SAP, Adobe, eBay, Atlassian, Expedia)
- Climbing Stairs (Apple, Amazon, Goldman Sachs, LinkedIn, Microsoft)
- Longest Palindromic Substring (Adobe, Airbnb, Oracle, Mathworks, Yahoo)
- Trapping Rain Water (Facebook, Twitter, Atlassian, Walmart Labs, Salesforce)
- Longest Valid Parentheses (Google, Amazon, Facebook, Apple, Microsoft, Uber)
As the name suggests, the greedy algorithm works on the principle of greed. At each step, we choose the option which gives us the most profit and proceed from there. It does not concern if the solution selected is best for the whole problem or not. And even if the earlier choice is wrong, there is no going back to change the decision. Due to this reason, the end result might not be the most optimal. Some problems are suited for the greedy method like Fractional Knapsack.
- Greedy – This playlist covers a lot of basic concepts regarding the greedy method. And also covers some important questions and how to solve these using the greedy method.
- Container With Most Water (Google, Amazon, Facebook, Oracle, Uber)
- Longest Palindrome (Google, Amazon, Intuit)
- Jump Game (Apple, Bloomberg, Adobe)
- Gas Station (PayPal, Microsoft, IBM, Expedia)
- Candy (Google, Microsoft, Amazon, Uber)
8. Sliding Window
As the name suggests, this technique contains a window and it slides across the entire data set. The sliding window technique can have a fixed-length window or a variable-length window. In the case of variable length, the window size can increase or decrease as per the requirement. The sliding window technique does the same job as the brute force approach but in a fraction of the time. This technique converts two nested for loops into a single loop.
- Sliding Window – This playlist covers sliding window in detail along with the different types of sliding window. It also covers a lot of important problems on sliding window. The playlist also covers some of the problems below with solutions.
- Contains Duplicate II (Google, Amazon, Adobe, Airbnb)
- Longest Substring Without Repeating Characters (Facebook, Apple, eBay, Cisco, SAP)
- Minimum Size Subarray Sum (Microsoft, Oracle, Bloomberg, Goldman Sachs)
- Find All Anagrams in a String (Intuit, Barclays, Accenture)
- Minimum Window Substring (Microsoft, Nutanix, Airbnb, Walmart Labs, VMware)
Also check: Machine Coding Round – What is it & how to crack it
How To Crack The Coding Interview
Now that we know what we need to prepare, it is up to you to put in the effort to prepare for the coding interview. Now we need to now focus on how to crack the coding interview. Writing the correct code is the sure-shot way to crack the coding interview. But it’s not that simple. You need to come up with the right logic first before you can write the code. And after writing the code, you need to explain the logic correctly to the interviewer.
We will go through some of the things you need to consider. It’s possible some of the pointers mentioned here are similar to what is mentioned in the article How to crack technical interview – Google, Amazon & more. But the pointers below are specific to the coding interview.
- After receiving the problem statement, go through the problem once to understand the ask. If you don’t understand something, re-read it.
- If you are still unsure of something, ask the interviewer for clarifications. Do not hesitate to ask questions.
- If you have some assumptions while writing the code, tell the interviewer about those. If they have any objections, they can tell you at the first stage itself.
- Don’t jump to writing the code directly. First brainstorm the approaches you can use to solve the problem. Why? There is no one approach to solving any given problem. The first solution might work but might also take time. Some other solution might be quicker and easier.
- Tell the interviewer about the approach you have in your mind. If they are okay with it, they might tell you to write the code.
- Don’t write the optimal solution directly. Even if you know the most optimal solution. Why? The interviewer might think you have mugged up the solution. Instead, start with the brute force approach and then work on optimizing it. That way, the interviewer might think you know the concepts.
- Don’t worry too much about writing fancy code. Focus on the core requirements first. If your code is not working, nothing else will matter.
- If the code is too lengthy, divide it into smaller and modular methods. It is more manageable and easy to read too.
- Even if you write a sub-optimal solution, but unable to write the most optimal solution, it is a win in most cases.
- When writing code, handle the edge cases efficiently. Don’t wait for the interviewer to point out the edge cases. Be proactive.
- Review your code once done. And don’t be in a hurry to tell the interviewer that you are done coding. Run your code against some sample test cases in your head or on paper. Do any corrections if needed.
- If you think you have written correct code and handled all scenarios, tell the interviewer you are done coding and ready for review.
- Explain the interviewer about your approach and the code. Tell them if you thought of some other approach too and why you think what you did is better.
- Run your code against some input in front of the interviewer. That way they can judge the code better.
- The interviewer might give some test cases of their own. Some test cases will work and some might not.
- If some test cases break your code, don’t panic. Just relax and think of how you’ll handle the cases which are breaking.
- Make corrections if necessary. There is nothing wrong with correcting your code or making minor tweaks if your code has some issues.
The best tip for the last. Be calm and confident. You have prepared for the interview well enough. So you will be able to crack the coding interview with ease.
All the best!!!
To keep yourself up to date with our latest content, please subscribe to our newsletter by dropping your email address here: Signup for Our Newsletter.
Please follow us on Medium.
- How to crack technical interview – Google, Amazon & more
- Machine Coding Round – What is it & how to crack it
- Digital Wallet Design – Machine Coding Round Solution
- Best Coding Platform To Become A Coding Expert
- Backtracking Algorithm Explained With Examples
- The ultimate guide to interview preparation
8 Replies to “How to Prepare for and Crack the Coding Interview”
I have been following you from quite sometime, you are doing a splendid job explaining lot of things in ur blogs. I even follow you on Quora
I had read your article about the best YouTube n other resources for cracking interviews
Algos from Abdul Bari, System design from Gaurav Sen.
But i don’t find that anymore.
Can you please send those resources on my mail ID if possible. It would be of great help
Thanks & Regards
Thank you Ashish for your kind words. It’s people like you who make all this effort worthwhile.
The links on coding and system design are still there, but this isn’t the article that had those links. You can still find them at How to crack technical interview – Google, Amazon & more.