How to solve any complex problem ?
Solve on a pen and paper. DO NOT start coding unless you are pretty clear with the logic of the problem.
Spend around 30–45 mins with every ques, not less not more.
Look into the solution/ editorial if you are not able to solve it. Let me tell you this, the challenge is not to solve on your own but to definitely solve it when you come across a similar problem for the second time. I used to hesitate in looking into the solution which wasted a lot of my time.
After you have solved the problem, analyze it completely, speak aloud and walk yourself through the naive to most optimised solution of the problem.
- Estimate the time and space complexities
- Check for any repetitive or unnecessary loops.
- Decreasing the time complexity with increment of space utilisation (Trade-off between space and time)
- Scrap this solution and think about new one.
#GoodLuck #Happycoding