Solving Problems Like Sherlock

KartavayKartavay
4 min read

WHY DO YOU NEED PROBLEM SOLVING

Now the fact that you are reading this article means that you know why you need them but still i will try my best to explain and make you feel more excited for being a better problem solver. It’s simple you are on hashnode that means you are a programmer and that also means that you definitely require problem solving approaches in order to solve the problems that come in your way. Problem solving helps you to better analyze a particular problem and then make some deductions just like Sherlock Holmes.

Move the SHIT around.

SO what does this mean after all we are not dealing with any shit here. The answer is correct but if you have solved some problems you know that there are times when you just fell into making some sub problems which had no relation to what you were aiming for and that is why we need to move the shit around. This basically means that in order to solve a problem better you need to figure out what you need to work on and what you don’t need to work on what you need to think about and what you don’t. And this my friend comes with practice so you have to practice a lot to know about what you need to skip (now don’t think that i was going to tell something that will take you there just by a slingshot).

FIRST GENERALISE THEN THINK ABOUT THE EXTREMES

This is simple have you ever found yourself in a condition where you are solving a problem and you got some solution but that did not work well? I am always there by the way. So in order to solve a problem well you first need to understand the question well you need to know what the hell it is asking for and soon i will be writing on that.

For example for this question we will start by thinking that okay what the question is telling us to do and if you have two eyes just like me you can easily see that it is asking us to check whether matrix can be obtained by rotation. Now we will start thinking:

  • I NEED TO ROTATE A MATRIX. WHAT IS ROTATION?

  • OKAY NOW I KNOW WHAT IS ROTATION, HOW DO I ROTATE A MATRIX.

  • THEN HOW WILL I CONVERT THAT INTO CODE?

After you go through this process you will have a decent idea how to do what is asked this was generalization then you will ask yourself that what if the matrix is already equal to the target (this is called thinking about the extremes). This was a simple example but i hope you got the idea. To put it again in simple words generalization is like looking at the forest from a drone but thinking for extremes is like zooming on a tree from above.

IF it can be done with a SINGLE VARIABLE then you don’t need two

Often times you may find yourself thinking about a lot of different variables take that you to the desired goal of solving a problem. But sometimes it is the case that you can do something or use some other approach that will take less variables or even a single variable. And our task is to exactly find a solution on how to do that. We should always be aiming for something that takes minimum efforts and gives us the same decent results like the approach we thought originally.

WHAT IF i am WRONG?

There are times when you have made some assumptions in order to solve something but you are not getting to the answer or in other words an elegant answer. Then it is the time to be humble. You have to start thinking that “what is wrong in my thinking?”. You need to think how your pre assumptions might be wrong and this is really important. Just like sherlock sometimes calls him idiot for thinking wrong and mending his approach you need to do the same.

INVERSION THINKING

This is one of the most effective ways by which you can solve the problems very well. Many times we are solving a problem but its solution is exactly opposite to what we have intended at the start. This has happened a lot with me and i guess you will pass through this also as you progress further in this journey.

OUTRO

These were some of the techniques I have learnt while solving problems on Leetcode. However i have solved few problems (just 50) so i know i am going to discover more problem solving techniques as I progress further. I will be glad to share those with you here…

0
Subscribe to my newsletter

Read articles from Kartavay directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kartavay
Kartavay

I write about things in order to make them INSANELY SIMPLE