How can one learn to solve algorithmic problems

Before you is a guide in order to learn how to solve algorithmic problems quickly and easily. Prepare for interviews properly.

For starters, if you think that learning basic computer science is enough to get you suggestions from different companies, you can finish reading here. This guide is designed for those who want to provide themselves with the necessary skills to have a LeetCode interview without any problems.

Hone your LeetCode writing skills is not just memorizing answers. You need to know the problem solving templates and be able to apply them. The number of tasks solved is just one side of knowing the templates, but learning involves more than just numbers.
Claim 0: Outside of basic computer science

This guide assumes that you have at least heard of basic things, such as double pointers and bit manipulation. You don’t need to know them perfectly, but at least basic knowledge of what they are will help you practice your LeetCode tasks more effectively. If you have only learned the basics of computer science, you may need to go to some books to get a little bit of pull.
Lightweight algorithmic tasks on LeetCode

Easy tasks are designed to help you learn basic techniques. Usually they have rough trivial solutions. You need to learn how to apply these techniques so that easy tasks do not cause you any problems.
Item 1: Practice Basic Tricks

If you accidentally open a few simple tasks from data structures or algorithms, you can easily and quickly come up with an optimal solution and then implement it, you can move on to the next point. If not, you will obviously have to linger and train harder to solve easy problems.
How to train

Sort the tasks by decreasing the acceptance rate. Usually tasks with higher acceptance rate are slightly easier.
Try to solve easy tasks without hints.
Oddly enough, it is not very useful to abuse the "run" button. Try to write a solution to an easy problem so that it is accepted the first time. This approach simulates the situation when you write code on the board, which will allow you to learn to look at all the options in your head.
Sometimes you should look at the solutions in the top to see if there are any interesting tricks. Often decisions fall into the top when they are short and poorly documented. Also, read the comments and feel free to ask for clarification.
Once you feel that you have studied enough solution templates for simple tasks, go back to step 1 and decide if you are ready to move on.

Average algorithmic tasks on LeetCode

Average tasks are designed for you to learn to see the essence. Most often they are different combinations of easy tasks. But “forehead” solutions can often lead to execution time errors. You need to be able to determine which solution template is required by this or that task.

Item 2: Recognition of task templates

If you accidentally open several average tasks from data structures or algorithms, you can determine what kind of tasks are represented in them, and implement a solution close to the optimal one within half an hour, then safely move to a higher level.
How to train

Carefully read the task text itself and look for implementation hints in it. For example, the number of subtasks may indicate dynamic programming, a string transformation with dictionary indicates a width search, a length search or a prefix tree, a search for repeating or unique elements indicates a hashing or manipulation of bits, etc. If you are looking for a more complete list of tricks, look out for a programmer's guide book.
When you have a rough idea of a solution, it's halfway through. Try to implement it, even if it is not quite optimal. This is normal, because people usually spend much more time on optimization than on the solution itself.
When you have implemented your non-optimal solution, take a look at the top solutions to the same problem to see how you can improve your solution.
Then try to understand the basic idea well and implement a more optimal solution without using hints.
Once you feel you can do more than just apply templates, it's time to move on to complex tasks.

Complex algorithmic tasks on LeetCode

How can one learn to solve algorithmic problems

Complex tasks are designed to make you tense. Usually 45 minutes is enough time for you to come up with a working solution. To learn how to solve them, you need to learn to see some more elegant ways than a trivial solution “in the forehead”.

Item 3: Last check

In complex tasks, there are usually limitations that prevent you from getting solutions using familiar templates. If you can modify the usual techniques to solve complex tasks, then your preparation is complete. Time is not so important here, you must learn to see the connection between familiar solution templates and these limitations.
How to train

In this case, solving the problem is more important than finding the optimal solution. If you can solve the problem "on the forehead" by sacrificing time and/or place restrictions, do so.
And only after that you need to determine how to optimize the solution so that it meets the constraints.
If you can't optimize the solution, it's time to pay attention to the top implementation options. Here it is very important to understand the course of the solution. You must learn how to select the right algorithm and use the right data structures, and be able to take into account all cases.
As soon as you learn to find solutions to some complex tasks, go to other types of tasks and try to make your solutions more optimal.

Thank you for reading this. I hope you have found something useful for yourself.