r/AskComputerScience • • Jun 29 '20

How to prepare for data structure and algorithms interview?

Hi there,

I am preparing for a technical interview in python. What should be my strategy be like.

How did you prepare for your technical interview? How can I make it more efficient? How many problems should I try to solve in a day? After how long being stuck should I look for solutions?

Thanks in advance.

31 Upvotes

12 comments sorted by

16

u/DrunkHacker Jun 29 '20 edited Jun 29 '20

1/ Practice coding on whiteboards. Thinking on your feet without an IDE is a wholly different experience. Plus, you'll learn to plan in advance and know where you want to leave additional lines for unknown code. Ideally, the first step of any answer should start with a function header and a return statement.

2/ Share your thought process with the interviewer. If they see you going down the wrong path, they'll probably be able to guide you with some questions. Also, if you happen not to arrive at the right answer, you may still get credit for "showing your work."

3/ Project Euler.

Source: I've conducted hundreds of new-grad interviews at both Big-Tech and my own startup.

Edit: words.

3

u/[deleted] Jun 29 '20

2) is a bit of a technique in itself. Things like TDD can be good for structure there: tell the interviewer how you understand what you're looking for by writing a test, then you get to either show you're great by executing your clear plan or show how you've got a process to identify and fix any issues you ran into.

1

u/DrunkHacker Jul 01 '20

This is a great idea -- verify a few inputs and outputs with the interviewer to ensure you understand the problem.

0

u/[deleted] Jun 29 '20

[deleted]

1

u/[deleted] Jun 29 '20

Could still be helpful if they throw a complex problem at you where cpu/memory usage are an issue. In a "force you to use an algorithm" type way.

7

u/realbhamshu Jun 29 '20

Strategy? Leetcode/ InterviewBit (choose one whichever you like).

How did you prepare? I like InterviewBit more because of their limited selection of problems and division by topics instead of by easy/medium/hard. I was very comfortable in coding in general before attacking DS/Algo so I could finish half of the problems on that site in about a week (10+ hours/day for that week). Apart from a couple of questions where it became a matter of pride to solve them, I'd never spend more than a couple hours on a problem.

How can I make it more efficient? After how long being stuck should I look for solutions? I'd suggest you don't spend more than 1 hour (or even less) if you have a lot of problems to cover. Better spend that time understanding the given solution since that's what the interviewer would be looking for (CAUTION: don't misunderstand this point. you don't have to (and cannot/ and it'll be counterproductive if you do) learn the solutions. Make sure you understand why every DS/Algo used in the solution was employed. Think about how you could have figured it out.* And most importantly, in your interview explain to the interviewer why you thought about doing whatever you're doing.)

How can I make it more efficient? How many problems should I try to solve in a day? Personal opinion but I believe intense practice gives O(n^2) output for O(n) work. So if you can manage an 80 hour week(80 productive hours; you'll have to sit for probably 100 hours for this), then you'd learn much much more than if you were to distribute them over a month. This is purely personal belief without any backing but this worked for me.

Task: Starting immediately, try to complete at least two problems from every bucket on interviewbit as soon as you can. If you know python well and if you have no other commitments you can very easily do this in one week. Look it up if you can't go anywhere even after 30 mins of concentrated deliberation.

* IF you do this exercise well, you can technically skip trying to solve the problems on your own entirely for your first hundred problems.

2

u/ACoderGirl Jun 29 '20

How did you prepare for your technical interview?

Honestly, in my case (working now at a big N), I mostly just reviewed the data structures and algorithms I already knew from their Wikipedia pages. I was only out of university a year and a half before I got into a big N, though, so everything needed was still reasonably fresh in my mind and just needed a refresh.

That said, that may not be the best for everyone. I did that largely to reduce pressure (cramming for interview questions is stressful). Practicing algorithm questions on the likes of leet code may be more useful. Especially if you don't have experience with them (in my case, I had done such interviews in the past and had done competitive programming).

How can I make it more efficient?

The algorithms or your process? For the former, knowledge of algorithm patterns is important, as well as familiarity with the types of problems that map to different solutions. Eventually you can get to a point where you look at a problem and you can just identify "oh, this is a dynamic programming problem".

For your process, try spreading your knowledge out across many types of problems and algorithms. Like, don't invest half your time in DP algorithms such that you have little experience with, say, linear programming.

How many problems should I try to solve in a day?

Above all, I'd say don't burn yourself out. That will just make things harder on the long run. Solving problems is a lot easier if they're genuinely fun to you. That may be possible when you just do one or two per day, but if you're grinding them, you're liable to get burnt out to the point of harming your mental health (leet code problems are stressful!).

After how long being stuck should I look for solutions?

An hour or so. Maybe 30 minutes if you're not feeling even close. If you have what you think is a good approach and just running into bugs when implementing it, I'd give yourself more time than if you're just spinning your wheels.

Bare in mind that interviews themselves are usually 45-60 minutes and sometimes only about 30 minutes is spent on the whiteboard. But also bear in mind that the interviewer should be giving you hints when you're stuck, so trying to solve everything without hints is unrealistic. Hints won't prevent you from being hired (I sure was given some hints during my interviews and still got the job -- your thought process and ability to explain it matters the most).

PS: don't forget that interviewers are ultimately trying to decide "would I want to work with this person". So they care that you can show them that you're smart, have versatile thinking, and come across like someone who can communicate well.