I have been meaning to say this for a long time now, but this post also pushed me to do it now rather than later! https://leetcode.com/discuss/general-discussion/935368/Help-in-getting-better-at-leetcode-contests
First some little background about myself I have been regularly coding on this site since January 2020, and have immensely improved my skills. I have participated in around 33 contests till now, & have been participating in all contests regularly since May.
I am currently hunting for internships, though I haven't had any luck so far, but I have been successful in nailing pretty much all Online Assessments ranging from RH codesignals to harder Fintech ones too, I can comfortably say that doing 4 questions in a contest is usually harder than most OAs.
The one thing I have felt that has helped me tremendously is participating in contests, and I cannot stress this enough.
Some reasons why contest gets you interview-ready:
- The contests simulate an environment that is almost identical to Online Assessments given by most companies.
- You are bounded by around 1 -2 hrs and you are asked to solve 2-4 questions.
- These questions progressively get harder in most cases, and you are able to skip questions.
- You being bounded by time while solving questions is very different from you strolling across your room and solving a random question on leetcode. You are not pressured to think continuously, your thoughts go everywhere and come back. When you force yourself to think in continuous bursts during a contest it's a lot harder.
- You have access to no question tags, no similar questions, no discussion post just like you wouldn't in a real OA.
- We are more prone to committing silly mistakes and getting brain freezes when doing things in a pressurized environment, and contests simulate this very well. You are a lot less likely to commit silly mistakes or gross oversights when you are leisurely solving on leetcode.
Finally, there is a popular saying among Navy Seals!
“We don't rise to the level of our expectations; we fall to the level of our training”
Some general tips for improving your contest performance!
(This is applicable for people that are just starting out Since I am not qualified enough to give any advice to peeps that are experienced. )
I have a very simple protocol for attempting every question i do during a contest:
- Read the question at least twice, you might not still get the question after reading it twice fully , it’s okay, proceed to the next step. Sometimes you catch the nuances by rereading a question that you miss on the first read.
- Understand ALL the test cases thoroughly, this is a very important step, This might fill some holes in your understanding. If you still don't understand, repeat these two steps.
- Once you are convinced that you understand both the question and the test cases, look at the problem constraints, and try to deduce the right complexity. This is important since you don't want to waste time unnecessarily optimizing a question where an O(n^3) logic would pass. Similarly, you don't want to code a logic that's O(n^2) when the expected complexity is linear. (I can elaborate more on how to deduce this complexity if you want)
- Once you have done this you can start thinking about the solution. The expected complexity is generally a huge hint in this, helps you to narrow down the patterns you can think about.(If you know the expected complexity sometimes it's almost like cheating)
- Don't start writing any code unless you are fully convinced and have thought about all corner cases, always be pessimistic about your solution and try to disprove it for some time before you begin writing code, this is because once you start writing code you take a huge risk, if at midway or even worse at submission, you realize that the logic you thought is wrong, you have already wasted a lot of precious time.
- Most code are writable in under 20-30 mins, If you have been writing code for more than 20-30 mins, try to think if there was any better way to solve it.
- Contest lets you know about the exact test cases you fail but most OAs don't, so getting into a habit of submitting the right solution in the first go is of utmost importance. No recruiter likes to call someone that managed to solve all questions with 20 wrong submissions. Moreover, you might not even know what cases you are failing in a real OA. The contest simulates this by penalizing you by 10 mins for each wrong submission.
- Always upsolve, Solve the questions you weren't able to do during contests.
- It’s okay to skip a question, Sometimes leetcode has questions with bad description, this happens in real life too, its better to move onto the next one, and come back to the question later.
- Don’t Give up till the last min, I have had so many photo finishes where I submitted a question in the last 2 mins.
- Practising implementation is as important as everything else, if you can write a bug-free code in 15 mins, it’s a highly beneficial skill.
- Keep solving problems on leetcode and set some weekly targets, the more patterns you practice the luckier you get.
- Don’t Cheat, sometimes there are solutions available when you search on google, If you start doing this there is no end to it, and your confidence will surely start to plummet, and every day you would feel like an impostor, plus it hurts your actual improvement chances by a lot.
- It's okay to fail, My contest ranking has been all over the place if you see my graph. Sometimes the luck is not on your side, which is okay, just keep trying honestly. Things do get better!
- Don’t be disheartened by repeated failure, If you are going through hard times, keep going, We all start from different places with different strengths, some of us are born geniuses some are just persistent enough. There is a quote by Seneca(The old guy in my DP)
“I judge you unfortunate because you have never lived through misfortune. You have passed through life without an opponent—no one can ever know what you are capable of, not even you.”
Please upvote this post if you find this useful, so it can reach others too!
If you would like to ask any further questions about this I am happy to answer!
Keep up the Grind :)