In most software and web development and software engineering job interviews, you will be asked questions that involve algorithms. From checking for duplicates or grouping items to implementing graph and tree searches, the interview questions will test your fundamental computer science knowledge.
Before you begin, you need to find out what sorts of algorithms the questions you're solving are asking for.
Then, when you understand the core algorithms and data structures, you can proceed to use a variety of websites for practising for the interviews:
- AlgoExpert (incredible videos to explain a lot of algorithms and to practice them)
- LeetCode (the gold standard for practicing algorithms interview questions, provides study plans)
- TopCoder (this site is more for competitive programming contests)
- HackerRank (site used for conducting interviews, has some great practice questions)
When you practice on one of these sites, you should practice in three ways. The first way is to recognize the problem types and then solve them completely, no matter how long it takes. The second way to practice is with a timer to be able to answer the question as fast as possible. This means recognizing which algorithm to use and applying it as quickly as possible. The third way to practice is to speak every step of the solution out loud. With these practice methods, during an interview you will be able to solve the problem within the timeframe given and be able to explain clearly to the interviewer how the solution works and why you implemented it that way.
This article also offers more ideas on what to practice: https://steve-yegge.blogspot.com/2008/03/get-that-job-at-google.html
Questions to Ask Yourself To Help You Solve The Algorithms/Data Structure Problem
Here are some questions to ask yourself:
- Have I seen a problem like this before from practicing?
- Do I need to use a hash table (or dictionary) to keep track of anything such as frequencies or counts or uniqueness?
- Do I need one, two or more "indexes" or "pointers" or "boundaries" to keep track of anything such as the positions in an array or the boundaries of a matrix?
- Is it possible to do any preprocessing on the inputs such as sorting or calculating anything based on them? Do I need a hash table or array for this? Is it okay to do the preprocessing in-place?
- Do I need to use recursion? What is the base case?
Top 10 Algorithms in Interviews
Here is a study plan based on this excellent article "Ace The Coding Interview Everytime".
This is especially useful if you are interviewing with Amazon, Facebook, Google or Microsoft (or any tech company that copies that interview process):
- Big O Notation
- Hash Tables
- Object Oriented/System Design
- Breadth-First Search (Graphs)
- Depth-First Search (Graphs)
- Binary Search
- Merge Sort
- Quick Sort
Use this study plan to find the algorithms questions and data structures that you should practice in each of the practice sites.
More Algorithms in Interview Questions
- Dijkstra shortest path search
- Floyd Warshall algorithm to find shortest path between any vertex
- Union Find for detecting cycles
- Minimum spanning tree
- Topological sort
- Inserting and removing a node
- Comparing two linked lists
- Math operations on numbers (where each digit is a node in a linked list)
- Detecting a cycle/loop
- Merge sort
- Shortest editing distance, changing characters or numbers to turn one object into another
- Sum of a subset
- Matrix array longest path
- Knapsack/backpack problem: placing items of various weightings into a limited size backpack, also known as the bin-packing problem
AlgoExpert is a little bit different from the other options in this list. It is a paid site where they give you multiple solutions with optimal space/time complexity. This is fantastic because you can demonstrate to interviewers that you know the trade-offs in memory or speed of particular algorithms.
CoderByte is a free site with a paid upgrade. They have lots of data structures and algorithms questions and multiple "interview kits" to prepare you for specific companies or specific technologies like React.
CodeWars has a series of katas for you to complete. Katas are exercises and some of them are algorithms questions, these are mostly just a good way to get warmed in a particular programming language. You should check out the other sites in the list for interview-specific questions to practice and for more explanations of solutions.
LeetCode is a competition coding site that features many many puzzles and coding challenges. They have multiple problem sets for algorithms so you can be prepared for your upcoming developer interview. This is where you can practice algorithms.
You can start with the basics like detecting palindrome numbers and merging two sorted lists and then move on to advanced problems such as solving sudoku and the smallest range covering elements from multiple lists.
There's a lot of ways to practice algorithms on LeetCode and you can use their built-in IDE to test and run your code multiple times.
Algorithms for Interviews in LeetCode:
- Graph Questions
- Dynamic Programming Questions
- Binary Tree
- Queues and Stacks
- Google Interview Questions
- Uber Interview Questions
- Facebook Interview Questions
- Apple Interview Questions
Buying the Premium subscription (monthly or yearly) for LeetCode gives you access to a lot of algorithms interview questions. Some of the question sets above may require a Premium account.
CodeSignal features interview practice questions and basic programming practice for developers. Companies sometimes use CodeSignal as part of their interview process so it's a good idea to practice at least a few algorithms problems on their site. The interview questions indicate the algorithm and the estimated time to complete the question, along with the estimated difficulty of solving the problem.
There are also hundreds algorithm question "challenges" that have been created by CodeSignal contributors: https://app.codesignal.com/challenges/page/1
CodeSignal Company Algorithms Questions
TopCoder is the classic algorithms site that features competitive programming contests. They have a gigantic problem archive that you can practice your algorithms skills with. You can search for problems to practice your dynamic programming, graph theory, and sorting and searching algorithm knowledge.
HackerRank features a large selection of programming problems and algorithm puzzles to solve. It is similar to CodeSignal in that it includes a section of problems that are similar to interview questions you may encounter.
HackerRank is used by a lot of companies to start the interview process so even if you don't think it's too good, you should still practice a few questions in it. This will prepare you in case a company you interview with is using HackerRank.
What's nice about HackerRank is that they also help you learn the algorithms. It isn't just for practising, it's also for learning. They have sections on specific languages too so you can brush up on whatever language is being used at the company you're interviewing with. You can also brush up on your SQL or Regex skills.