Reference implementations of key algorithms, suitable for coding interviews and easy to extend/adapt for specific problems.
I adapted these from various sources while preparing for coding interviews during a job search (successful!).
Here's the idea:
- I found that almost all coding questions used one of several basic algos.
- But, even though I knew those algos, I was spending too much time re-writing them during interviews, and I was making too many mistakes.
- So, I created these reference algorithms.
- I practiced them until I could type them out, from memory, quickly and without errors, and I used them in all of my interview prep.
Here's how I recommend practicing them:
- Pick an algorithm (
ref_*.py
). Make sure you understand it via whatever class/bootcamp/book you're using (see below for suggestions). - Copy it into practice.py.
- In practice.py, delete part or all of the code above
def test():
. - If you try to run the file now, it will fail, of course.
- Now, try to re-write the algorithm, exactly, from memory.
- If you get stuck, look at the original copy, and read ahead to try to re-memorize it.
- Just try to minimize how often you have to look at it.
- Once you've re-written it, try to run the file, and make sure the 'tests' pass.
- If you had to 'cheat' and look at the original copy, then once it runs, just start over with that same algo.
- Keep starting over with that same file until you can write it quickly, without errors, so that practice.py is exactly the same as the source file.
- Each day, do this with one or more algorithms. Each time, it should go faster, until you can basically write them out at the speed you type.
- As you practice your coding interview questions (e.g., at leetcode), try your best to adapt these reference algos to the problem at hand.
I found this to be incredibly effective. Interviewers are really impressed when you can type out an algorithm like BFS or DFS very quickly, cleanly, and without errors. Then, you have the mental bandwidth to engage with the details of the actual interview problem.
- I strongly recommend the course at Interview Camp ( https://interviewcamp.io/ ). These algos are adapted quite closely to that course, and you'll get the most mileage out of them if you use the two together.
- Practice tons of questions at Leetcode ( https://leetcode.com/ ). Just buy the premium membership; it's such a small cost compared to the benefits of acing these interviews.
- Practice a few live interviews at Pramp ( https://www.pramp.com/ ), a free peer-to-peer platform for practicing coding questions. It will help you practice your pacing, get over your nerves, and see what if feels like to be on the other side of the table.