These are the data structures to keep in mind and try, in order of frequency they appear in coding interview questions:
candidates should start by asking clarifying questions and discussing a few possible approaches with their interviewers.
1. Visualize the problem by drawing it out
Whiteboards make it easy to draw diagrams which helps with problem solving!
A huge part of coding is understanding how the internal state of a program changes and diagrams are super useful tools for representing the internal data structures state.
2. Think about how you would solve the problem by hand
Solving the problem by hand is about solving the problem without writing any code, like how a non-programmer would
If you can come up with a concrete set of rules around the approach that works for every example, you can write the code for it.
Coming up with more examples
It helps you to reinforce your understanding of the question, prevents you from prematurely jumping into coding, helps you to identify a pattern which can be generalized to any input, which is the solution!
If the problem is large, start with a high-level function and break it down into smaller constituting functions, solving each one separately.
Hash Maps: Useful for making lookup efficient. This is the most common data structure used in interviews and you are guaranteed to have to use it.
Graphs: If the data is presented to you as associations between entities, you might be able to model the question as a graph and use some common graph algorithm to solve the problem.
Stack and Queue: If you need to parse a string with nested properties (such as a mathematical equation), you will almost definitely need to use stacks. Heap: Question involves scheduling/ordering based on some priority. Also useful for finding the max K/min K/median elements in a set. Tree/Trie: Do you need to store strings in a space-efficient manner and look for the existence of strings (or at least part of them) very quickly?
Sorting Binary search: Useful if the input array is sorted and you need to do faster than O(n) searches Sliding window Two pointers Union find BFS/DFS Traverse from the back Topological Sorting
The Best Theoretical Time Complexity (BTTC) of a solution is a time complexity you know that you cannot beat.
The fastest practical solution can only ever be as fast as the BTTC
Choice of data structures is key to coding interviews
It can help you to reach a solution for the problem, it can also help you to optimize your existing solution.
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.