How to prepare for data structures and algorithms interviews

career advice College computer science interview prep technical interviews
By Alena

When preparing for data structures and algorithms interviews, it’s crucial to put in time reviewing concepts and solving practice interview problems. However, it’s almost equally important to practice the structure of the live interview itself. Here are some tips for communicating and organizing your thought process as you’re being interviewed.

Check your understanding of the question

After the interviewer presents the problem to you, restate the problem in your own words to make sure your understanding matches the interviewer’s. If an example hasn’t been provided, consider providing your own small input and the expected output/behavior.

Now is a good time to clarify inputs and outputs. Think through special input cases (ie negative numbers, duplicates, empty inputs) and ask the interviewer about them. What is the desired output/behavior in that case?

One step at a time

It’s easy to feel overwhelmed and not know where to start. Remember, you’re not expected to think for one minute and write down a bug-free runtime-optimized solution. Interview problems are expected to be solved in stages. The next few steps describe some possible stages for thinking through the solution.

Describe the naive solution

Describing the simplest/brute force solution and its time complexity is a great place to start. The brute force solution is often a seed idea for more optimized solutions, and defining the brute force complexity gives you a benchmark to beat and demonstrates that you are already thinking about efficiency.

Think aloud through the problem

Thinking aloud is one of the hardest aspects of the coding interview process – we’re not used to narrating our own thinking process. I’d recommend that you practice thinking out loud while working on practice interview questions at home. 

If you’re not sure where to start on the problem, start simple and talk through elements you know the solution will have. Here are some things to think about (and describe out loud to the interviewer as you’re thinking about them!): 

  • What data structures could be useful?
  • Is there a related algorithm?
  • Out of common tools (for example, DFS/BFS traversal, dynamic programming, sliding windows, binary search), do you have ideas about which would be useful? Which ones won’t work, and why?

consider asking for input

If you feel you’ve stopped making meaningful progress in the interview, consider asking for input from the interviewer. Getting a hint and getting on the right track is definitely better than going down a path you suspect isn’t correct, or not making progress at all. Remember, the ability to self-correct is valuable as well! Asking for direction could look like this: “I tried to optimize the solution by keeping a list of already visited states, but I think I’m missing a more meaningful optimization. Is there an example input that might help me think of areas for further improvement?” 

Before writing code

At some point in the interview, you’ll have sketched out an idea, and your interviewer will ask you to write some code. It’s super tempting to jump in and get started as soon as possible! However, I’ve often seen candidates jump into code for a complex algorithm, then get slowed down setting up initial data structures/frameworks they discover don’t work as they progress in the solution. I recommend taking the time to define some details before coding, for example (depending on the type of problem):

  • What data structure will you be tracking visited states with? 
  • What data structure will you use to keep track of solution candidates? 
  • What are all the methods this class will need? 
  • What state does the class need to store? 
  • What is the stopping condition? 
  • How will you traverse the data structure?

 

Taking the time to lay out these details ahead of time, whether it’s in pseudocode, notes, or talking aloud, can help you avoid going down rabbit holes of unnecessary complexity.

Talk through the solution

After you’ve written the code, talk through the execution of your code on a small example input. This will help you catch bugs you’ve written or see areas of improvement.

Unit tests

If you have time at the end of the interview, think about unit tests you would write. Depending on the format of the interview, this could be verbally describing test cases, or if you’re using a coding platform, writing executable unit tests.

Remember, the coding interview is a flawed, probabilistic process, but with preparation, you can change the probability distribution. Good luck!

Comments

topicTopics
academics study skills medical school admissions MCAT SAT college admissions expository writing strategy English MD/PhD admissions writing LSAT physics GMAT GRE chemistry graduate admissions biology math academic advice law school admissions ACT interview prep language learning test anxiety personal statements premed career advice MBA admissions AP exams homework help test prep creative writing MD study schedules Common Application computer science mathematics summer activities history secondary applications philosophy organic chemistry research economics supplements 1L grammar PSAT admissions coaching dental admissions psychology statistics & probability law legal studies ESL CARS PhD admissions SSAT covid-19 logic games reading comprehension calculus engineering USMLE mentorship Latin Spanish medical school parents AMCAS admissions advice biochemistry case coaching verbal reasoning DAT English literature STEM excel political science skills French Linguistics MBA coursework Tutoring Approaches academic integrity astrophysics chinese classics dental school gap year genetics letters of recommendation mechanical engineering units Anki DO Social Advocacy algebra art history artificial intelligence business careers cell biology data science diversity statement first generation student geometry graphing kinematics linear algebra mental health presentations quantitative reasoning study abroad tech industry technical interviews time management work and activities 2L AAMC DMD IB exams ISEE MD/PhD programs MMI Sentence Correction adjusting to college algorithms amino acids analysis essay athletics business skills cold emails executive function fellowships finance freewriting functions information sessions international students internships logic networking poetry pre-dental proofs resume revising scholarships science social sciences software engineering trigonometry writer's block 3L Academic Interest EMT FlexMed Fourier Series Greek Health Professional Shortage Area Italian JD/MBA admissions Lagrange multipliers London MD vs PhD Montessori National Health Service Corps Pythagorean Theorem Python Shakespeare Step 2 TMDSAS Taylor Series Truss Analysis Zoom acids and bases active learning architecture argumentative writing art art and design schools art portfolios bacteriology bibliographies biomedicine brain teaser burnout campus visits cantonese capacitors capital markets central limit theorem centrifugal force chem/phys chemical engineering chess chromatography class participation climate change clinical experience community service constitutional law consulting cover letters curriculum dementia demonstrated interest dimensional analysis distance learning econometrics electric engineering electricity and magnetism escape velocity evolution extracurriculars fundraising genomics harmonics health policy history of medicine history of science hybrid vehicles hydrophobic effect ideal gas law immunology induction infinite institutional actions integrated reasoning intermolecular forces intern investing investment banking lab reports letter of continued interest linear maps mandarin chinese matrices mba media studies medical physics