This blog is a guest contribution from Algodaily.com
The way most people study/prepare for technical interviews with coding problems isn’t conducive. An average person will go on a site like HackerEarth or AlgoDaily and will only spend a few minutes actually trying to solve a problem.
Often, they’ll then jump to the solution after getting stuck. Then they’ll read the solution, try to memorize it, and call it a day.
A better way to prepare
Here’s a more effective way, and it’s why the AlgoDaily system was designed the way it was:
First, choose a cadence
One interview problem a day seems to be the ideal amount. If you do 2 or 3 a day in the manner described, you’ll be spending 3-4 hours doing it, which is quite ambitious unless you are preparing full time.
It’s also mentally tiring, and you are unlikely to derive a whole lot of marginal benefits from the 3rd or 4th problem. At a certain point, you’ll probably begin to eagerly jump toward obvious solutions, which will not help you understand where your strengths and weaknesses lie.
The below suggestions nudge your thought process toward retaining the patterns and eventually help you solve problems you’ve never solved prior.
Commit some time and try to solve the problem by yourself
Before jumping to the solution, dedicate about 20-30 minutes to a problem and try to solve it all by yourself. Try to get some semblance of a correct output.
Brute force it if you have to—try to reason about any working solution, no matter how slow it is. It will help you understand the necessities to optimize it later.
Don’t fret if you get stuck
If you’re stuck at a problem, restart by looking for hints and then keep trying to solve it. Repeat until there are no more hints.
When you run out of hints, start going through the problem statement or solution very slowly. As soon as you are unstuck, STOP READING. Use the bit of insight to start coding again.
Anytime you get stuck again, repeat from the beginning
Even though you’ve read a part of the solution, the vast majority of learning comes from the struggle of thinking it through yourself. That is what will help you retain it for the next time.
Here are some additional steps that really made the difference in my prep:
- Write the solution again in another programming language. This will let you think through the abstractions again and help with retention
- Save the problem and revisit it in increasingly long spurts. This is called spaced repetition, a technique employed in the AlgoDaily technical interview course. For example, you may want to try to solve a problem today, again in 2 days, then revisit in a week, then a month.
Some questions to ask at each step:
- What have I learned so far? Is there anything I should know for solving the problem the next time?
- What pattern or technique was the solution derived from?
- What hint did I need? How far was I from solving it myself?
- If asked the same question tomorrow, can I readily solve it without any assistance?
Before we jump into the importance of mock interviews, here are some things you must cover.
Without a solid understanding of the following concepts, you may struggle during mock interviews:
- Hash Tables: This is arguably the most critical data structure. Make sure you can implement one from scratch.
- Stacks/Queues: It is important that you know these data structures such as FILO and FIFO
- Linked Lists: Know about singly linked lists, doubly linked lists, and circular.
- Trees: Get to know basic tree/node construction, traversal, and manipulation algorithms. Learn about the subsets—binary trees, n-ary trees, and trie-trees. Lower-level or senior programmers should know about balanced binary trees and their implementation.
- Graphs: Learn about implementations (objects and pointers, matrix, and adjacency list) and their pros and cons.
- Sorting: Get to know the details of at least two n*log(n) sorting algorithm. I recommend Quicksort and Mergesort
- Binary Search: Binary search is the most popular search algorithm. It is efficient and also one of the most commonly used techniques that is used to solve problems
- Tree/Graph traversal algorithms: Breadth-first Search and Depth-first Search are musts. Also know inorder, postorder, preorder.
- Basic discrete math (logic, set theory, etc.)
For this knowledge, the best way to study might be the flash-card style. There are tons of flash-card applications online, and there are many guides and quizzes at AlgoDaily. You could also pull in a friend to conduct a mock interview, speaking of which—
Mock interviews are key.
You must practice some mock interviews before attending an actual interview. Ideally, this would simulate as much of the real interview as possible.
If it’s a whiteboard interview, grab a whiteboard and a knowledgeable friend, and force yourself to answer random algorithm/data structure questions from them.
Here are a few things to keep in mind while practicing mock interviews:
- First, ensure that your friend or pairing partner is also a software engineer, preferably of the same level as you. He/she should be comfortable breaking down a problem into hints for you.
- Have a timer available. Limit it to 30 minutes as most companies’ interviews last around 45-60 minutes. This additional time will help boost your confidence for the actual interview day.
- Your mock interviewer should not be looking for the correct answer immediately. Have them evaluate your approach: did you ask the right questions to understand scope? Did you have a brute-force solution within the first 5 minutes? Did you write pseudocode to get your thoughts down? Are your test cases adequate and covering all edge cases?
- Ensure that the challenges being covered are among the more common ones to ensure you’re being efficient with study time. AlgoDaily’s free challenges can be useful for this.
- Write down all feedback and try to improve in the next mock interview.
- Also, take turns interviewing. Being in the interviewer’s seat will help you understand what companies are looking for when evaluating a candidate. It will also help you realize how difficult it is to be an interviewer, and ease some of the nerves when you realize they are working hard to help you solve the problem.
Check out HackerEarth for some fantastic resources that I’ve used when preparing for mock coding interviews. The competitions really help with time management and on-your-feet thinking that you’ll need.
Best of luck and happy coding!
AlgoDaily provides a visual technical interview course. HackerEarth members can email firstname.lastname@example.org for a discount.