Whats the best way to practice leetcode?
As of this date, I've been semi-consistently practicing leetcode. I do it when I can, and when I'm not too drained from the day.
I recently had a conversation with a friend, reminiscing about the time long ago when I was doing math practice at my tuition teacher's house. It certainly was very gruelling - out of the 3 hours or so spent there, 30 minutes was dedicated to learning about the topic, and 2.5 hours was dedicated to practicing learned concepts.
I remember each student in her class being given a photocopied page of the textbook practice page for the topic being taught that day. You know, the page at the back with questions ranging from "basic" to "put on your thinking caps!".
What she would do is let us off for a 5 minute break right before we commenced that practice session, and after she completed teaching that topic.
We'd come back from the break, and each person would have a textbook as well as the photocopied practice page. There'd also be an oreo packet or some snack, all placed neatly for everyone.
We'd start doing the topic, and this is the key part - I now remember flipping back and forth from the practice questions and the formulae in the book. Why is this key? This is key because my mathematical agility and accuracy increased slowly but surely, and by the end of that practice session, I felt like I knew how to apply the concept to any question of decent difficulty. Did I prevent myself from looking back at the answer? No! Each time I forgot how to apply the formula, I just looked back at the topic, and eventually the mind would just start remembering the formula, after continuous practice.
Looking at the answers¶
Much like leetcode, when attempting a new topic in the Neetcode 150 list, somehow I never knew how much overthinking I was doing - preventing myself from looking at the answer. Eventually I learned to understand that the answer itself was the topic notes. I'm not going to be able to answer the question no matter how hard I try if I just dont understand and remember the formula. Let the remembering and understanding come naturally with practice, and practice should stay as practice, not a mock test.
Writing Java vs writing algebra¶
Another factor at play is my foundational ability to implement whatever solution in my head onto the question before me. Much like how solving a trigonometric problem involving algebraic formulas is not possible if I'm not at least decent in algebra, I'll have a really hard time trying to remember so many things at once. The formula, the concept, the language. Too many things at once, stemming from a lack of practice of foundational grammar, will muddy the learning process of the core topic at hand.
How do I then tackle topics?
While thats a question I'm still in the process of answering, I'll be trying to focus on the learning of the topic at hand first, instead of trying to tackle everything at once.
This means spending some time at least to understand the question, then seeing the answer. Then trying to apply the answer by "flipping back and forth"!
I'll tag the question as completed, but I'll also note that it was my first time completing the question (for that topic). I will then try to reduce the time taken to complete the question in the future, and log every future attempt.
Notes on the question should be written somewhere, with intent. I will keep a notion tracker to read my notes on each question.
Another thing I did remember from her practice sessions was this - she'd go through select questions in the practice page in the last 30 minutes of the class. While she didn't tell us explicitly why she did this (we also didn't question it), I can only reverse engineer her rationale. That is, she did it because those questions specifically are just a little bit off the standard solution for the questions.
I also remember skipping some questions and going on to the next question. Time was of the essence, and I didn't want to miss the forest for the trees by spending time grabbing the high hanging fruit when there are so many other low hanging fruits ahead.
Don't beat yourself up over the high hanging fruit that you couldn't get, be happy about the fruitful harvest.¶
In short, practice a particular DSA topic like its a harvest. I'm looking to be generally good at answering most of the questions. I'm not looking to prove to myself that I can answer the tricky questions - those are the questions you'd skip and instead wait for her to go through in the end anyway.
The key in this case is to use the questions again as practice, this time without looking at the answer, and having a timer to solve the question.
Oh yea, I almost forgot to mention one thing.
Feeling tired?¶
It's. Normal. To. Feel. Tired.
I dove deep into my own memories and I realised that once a week out of the 3 math tuition sessions, the day would just be so hectic, and I'd come to her house really nasty and having that sweaty, secondary school kid smell. God was it gross.
Thankfully, I can avoid that now, at least to that degree of nastiness. A little sweat should be fine. But the main point is - those days I recalled being so tired, and I would be fighting to keep my eyes open during the session. However, her strictness, which manifested in short and sharp callings of whoever is falling asleep, combined with a "Lets try to complete this practice page" mentality, allowed me to push through (yes I was sent to the washroom to wash my face and come back) and complete the session.
As such I think that having a clear goal for the session (complete 3 questions to gain an understanding of the topic) and having a set session time are key things that would really help. It would help stave off the "oh lets just do it tomorrow" or "I'm so sleepy - you need a break" mental voices. Of course also setting time aside to just do this and not letting other stuff overlap into this time are also key!
This is a key issue that I realised when trying to practice during internship times. I set my leetcode session in the morning but I'm usually rushing to complete something for my job in the morning. Hence I end up doing leetcode at night, and lacking much planning as mentioned above.
FInal thoughts¶
There are a lot more things that I was thinking of talking about, and I wish I had the ability to turn my thoughts concisely into text. For now, here's a quick and dirty summary
- Practice leetcode consistently, like the routine math tuition sessions.
- Practice with the purpose of learning how to apply the new topic, instead of the practice being a test of your abilities (if doing a new topic).
- It's normal to feel tired - have a set time aside and do not let this time be used for anything else. Wake yourself up if you have to because you need this time to just practice.
to be updated (or not!) if I have time but so far these written thoughts will suffice for now :)