How to solve problems on Leetcode/HackerRank to prepare for a tech interview

This article helps you with how to prepare for a technical interview

how to solve problems to prepare for a tech interview

Have you ever asked yourself this question? I think so; that's the first question at the start of your journey. Although the process often looks like a forest in which it's easy to get lost. I give you the plan and method of how to prepare. By following the instructions, you're guaranteed to get results.

My plan combines approaches from "Cracking the coding interview" and leetcoder's recommendation.

Track of your progress

Before solving any problems on LeetCode/Hackerrank, think about how you keep track of your progress. Create yourself a progress sheet with properties: problem title or link, date, topics, attempts. You can create an excel sheet or use my Notion Template for it (link).

Understand problem

It's not a simple step. You have to understand the problem. Read the task description carefully: your main goal is to understand all possible cases. Think about all possible examples. Ask yourself the following questions:

  1. What data are available?
  2. What kind of relationships do the parameters have?
  3. Do you need immutable or mutable data?

High-level algorithm

Create a high-level solution as soon as possible. Create a naive algorithm with a lot of issues with optimization; it's not a big deal! But each time for every solution - explain what the space and time complexity is.

Review and Optimize

The next step is to review your algorithm and think about what you can improve. Find bottlenecks inside your algorithm and try to resolve them. Also, remember to clean up your code from unnecessary actions such as unnecessary duplications, useless calculations.

Test yourself

For me, the last but not least step - testing. Be careful and check all cases from the second step. Start with conceptual tests and only then move on to special cases.

Further Reading