DEV Community

Cover image for How to solve medium leetcode problem?[need help]
Mohammed Awad
Mohammed Awad

Posted on

How to solve medium leetcode problem?[need help]

I don't know if everyone has this problem but I took a long time to solve a medium problem in leetcode sometimes.

I needed 10-15 minutes to understand and make some ideas and maybe can not had any idea how to start until I see hints but mostly passed with 70%-80% of the tests then gave up and used ChatGpt to get a solution. with easy questions took a couple of minutes and sometimes 20-25 minutes, depending on the idea

For example I learned about the 2-pointer technique then tried solving a problem starting with the basics and init the left and right pointers then got stuck with passing all the tests what should I do with conditions that solve the problem and pass all the tests

until now I have solved 12 easy and 6 medium problems

** What should I do to be better ?**

Top comments (4)

Collapse
 
joshduffney profile image
Josh Duffney

Hey Mohammed, I've been following the Neetcode roadmap to keep me gradually progress in a logical way. Some advice I've also picked up from others is: If you can't solve it in 45 mintutes. Stop and study the solutions of others. Then go back and solve it using there solution. A lot of the medium and hard questions use advanced algortihms that you're unlikely to come up with on your own. And your time is better spent understanding existing solutions and how to use them. That way you can add them into your mental toolbox so to speak.

Here's a link to the neetcode site. neetcode.io/roadmap

Collapse
 
xmohammedawad profile image
Mohammed Awad

Thanks, nice idea, because really when see other solutions I find them using the same technique sometimes like I mentioned `2 pointer' I will check the neetcode

Collapse
 
xmohammedawad profile image
Mohammed Awad

Any help ???

Collapse
 
ghubrakesh profile image
ghubrakesh • Edited

From my personal experience-

Don't just hop on to medium problems directly. Solve some easy problems first, then go for medium ones.
Also, notice the intuition of the problems. What are the different approaches that can be used to solve the same problems?
Some problems also include brainstorming, and some of them are totally different from others, if you don't have solved similar problems, most probably you are going to think and just think, but you will find it difficult (nearly impossible) to solve them.
conclusion: Don't focus on solving the problems at first, focus on understanding the algorithms.