All of the leetcode questions that I have solved.
I have tried to add multiple approaches to each answer wherever possible. Also,tried writing the TC and SC on top. Although the format may be messy or uneven, I think it is still easy to grasp. Even if it isnt, you have no choice. xp.
You can use leetcode-timer extension to track the time spent on each problem.
For any problem, follow this approach for better efficiency -
-> Read and understand the question, test your understanding with the sample test cases.
-> Make your own logic on pen/paper or in your mind. Come up with a pseudo code for it. Test it with the sample cases.
-> Implement the code.
-> Test and debug. Try to add edge cases.
-> Calculate the space and time complexity.
-> Think for an optimised approach.
-> Repeat from step 2.
Some important tips -
- Make sure you keep time in mind while solving problems. Always try to solve the problems first on your own but dont spend too much time if you are stuck.
- If you think the question is doable and you know the concepts, but your brain feels like being frozen, just brute force it. Remember, every problem is doable. Its all about the mentality.
- After using brute force, it is likely that you may get TLE. So, you need to come up with a better approach. But now atleast you have some understanding, control and confidence of the problem.
- Now, you can either check the hints/topics. You can go to the description but dont go to the solutions until you have come up with an accepted one by yourself.
- Even after this, if you are stuck. You can save the question for later. Make a list in leetcode for questions to revisit.
- OR if you think the topic is relatively new to you. Read about the topic. Try solving similar questions probably. And then attempt. Reading the solution should be the last resort.
- But at the same time, once you have come up with YOUR solution, I think its a good practice to see solutions which took less time. Try out editorial or solutions for this purpose.
Some days, leetcoding may feel overwhelming, draining or demotivating, but you need to remember thats natural. This shouldnt stop you. Your task is to keep moving ahead till all of the questions are finished. This is similar to life, some problems feel like mountains. But every mountain can be climbed as long as you have the drive. And anyways this is just maths, logic and coding, this is relatively fun, you dont have any right to complain here. It wont get any easier. But you will get stronger. So, dont think and just do it. (I dont wanna make this more cringier so ill stop.)
Have a nice day and happy leetcoding!
Created using LeetHub