Master Problem Solving in Data Structures & Algorithms

Tushar Patil
4 min readJul 27, 2022

--

Master Problem Solving

I have solved more than 2000+ problems on coding platforms like Leetcode, Codeforces, Geeksforgeeks, etc. And these tips helped me to become better problem solver. So, try them and you’ll see a huge improvement in your problem solving skills.

💡 Tip-1

DO NOT FEAR ANY PROBLEM.

Most people give up without trying. Every problem which is given to you (by interviewer or some website) can be SOLVED. This is the mindset which you must have in order to solve the problem.

💡 Tip-2

Clear your basics.

Naval Ravikant once said “I would rather understand the basics really well than memorize all kinds of complicated concepts I can’t stitch together and can’t rederive from the basics.

Before solving any question, clear your basics of that topic. And then try to solve it.

For eg: You cannot solve a Graph problem, if you don’t even know how to implement them.

💡 Tip-3

Understand the problem fully.

Avoid skimming the problem, read the problem properly twice or thrice (if necessary).

💡 Tip-4

MOST IMP: Use Notebook while solving a problem.

A single sheet of paper can’t decide your future, but it will surely improve your problem solving skills. So, avoid solving problems in the mind and start writing the logic on the notebook.

💡 Tip-5

Figure out how the answer to the given test-cases is forming.

After reading the question, check the test-cases. Just try to get an idea about how the answer to a test-case is forming using manual calculation.

💡 Tip-6

Figure out which Data Structure(s) or Algorithm(s) can be used.

Check what operations you need to perform in order to solve a problem. And check which Data Structure(s) or Algorithm(s) is suitable to perform those operations.

For eg: if you need to deal with unique elements, then you can use Set Data Structure in that case.

💡 Tip-7

Break down the problem into smaller sub-problems.

If the problem is too complex, then try to divide it into sub-problems. And solve those sub-problems in order to solve the ultimate one. You can create different functions for the sub-problems and you’ll form a habit of writing clean code.

💡 Tip-8

Check the output for n = 0, 1, 2, 3 and so on till you find some pattern

If the problem is based upon some observations, then try to figure out the pattern. Try to find the answers for n = 0, 1, 2 and so on.

💡 Tip-9

Most of the problems are built on top of few fundamental problem(s).

Always try to use fundamental concepts to solve a problem. Try to relate the current problem with the problems you have solved in the past.

For eg: if the question is based on Trees/Graphs, then there is huge chance that it is based on BFS or DFS pattern.

💡 Tip-10

Try to come up with the Brute Force approach and then try to optimize it.

Never try to find the most optimized solution in the first go, otherwise it will become very hard to solve that problem.

For eg: In order to solve a Dynamic Programming problem, first you need to come up with brute force recursive approach and then you will try memoization on it.

💡 Tip-11

Use HashMap to reduce time complexity

If you need to reduce the time complexity then store your previous answers in Hashmap. Because in Hashmap we can get the access to an element in O(1) time complexity.

Try 2-Sum problem in order to understand it properly.

💡 Tip-12

Accepted is Not Enough

You solved a problem by your own?

WELL DONE. But that’s not enough.

Check the discussion forums (even after getting accepted) in order to find the most optimized solution.

For eg: the above problem (2-Sum) can be solved in O(n²) easily. But that’s not enough because it can be solved in O(n) using a Hashmap.

So, these were some of the tips which I used in order to become better problem solver.

About Me

I am Tushar, a software engineer at Cisco. I started my journey back in 2020. With a tier-3 college tag and Non-CS branch I managed to get into tech after working on my skills for more than 2 years.

DM’s always open on Twitter & LinkedIn.

Best Luck For Your Journey :)

--

--