Prepare for Coding Interviews, not Just Solve LeetCode Problems

coding problemsinterviewsleetcode

Practice makes perfect

Photo by Brett Jordan on Unsplash

The coding section on interviews is not about pure knowledge of algorithms and data structures. It is actually, but interviewers also look for signals from candidates to estimate problem-solving skills, level of technical competency, how they communicate, and so on. And our goal is to develop a habit to provide such signals every time you are practicing.

Time is important

Time flies, especially on interviews. On average, you have about 45 minutes for coding out of an hour interview. To get used to it, set up a timer before solving a problem. I noticed that 30 minutes timer helps me to prepare for such a tight timeframe.

Understand the problem

Read the problem carefully, and repeat it back. I talk to a rubber duck, it looks strange, but it works. The next step is to clarify things like the format and range of the input. LeetCode has examples and constraints sections, don't ignore them. At last, go through a small sample to ensure that you grasp the problem.

Devise a plan

First, describe an initial idea of how you are going to solve the problem. Explain it to the rubber interviewer, even if it is a brute force. Second, try to improve the idea and come up with a better solution. Use comments in an editor to write down the steps to implement your idea. When you finish an algorithm, tell the interviewer about the time and space complexity and that you are ready to write code.

If you are stuck figuring out a solution, try to recall similar problems and how did you solve them. If you are still stuck, check for a hint on the platform.

Communicate while coding

Ok, it is time to write code. Explain everything you are coding and what you want to achieve. Type at a reasonable pace, use proper variable names and indentation, extract functions if needed, show knowledge of a programming language you use, be proactive. When you finish, don't push the «run» button right away.

Check the code

Look at your code and check for errors, like array boundaries in a loop, redundant conditions, missing parenthesis, etc. Go step-by-step through your code with the examples you have, then create some more inputs to check edge cases. Do not forget about the timer! If you are short on time, explain where you cut corners and what you would do in another way to make the code better.

Run the code

LeetCode lets you test code against custom inputs, so try all of your examples and then submit. If the solution is accepted, well done. If it doesn't, return to the previous paragraph.

Sometimes, interviewers prefer to use Google Docs or similar as a code editor, so there is no «run» button. Therefore, you tell the interviewer that you finished coding.

Homework to do

After practice, record the problem you solved, a brief review of the solution, data structure, and algorithm you used. A stylesheet or notion will be helpful. Such a journal will help you track your progress and quickly recall the problems you solved right before an actual interview.

Main page