I’ve heard a lot about Leetcode and decided to give it a try. A dozen problems in and I’m finding it a hub of interesting, fun and complex problems that rely on knowledge, logic, and lots of creativity. From stock trading, ransom note creation and candy allocation, not a dull problem.
It took trial and error to figure out how to use the platform effectively, and I wanted to share my insights.The barrier to start tackling LC problems is rather low. Here is what I think is essential:
- Working knowledge of one language: it does not have to be an advanced command, but you have to know enough syntax, functions, etc. that when a new element of said language crosses your path, you can quicly research, understand and employ it. Familiarity with debugging helps. More on languages below.
- Some math: There is a wide variance in the mastery of math required. Problems labeled “Easy” need very little. As you go for medium and hard problems, expect to teach yourself new concepts.
- Logic and Discrete Math: Be prepared to learn some notations, and read proofs. Often, this isn’t explicitly mentioned, but the solution to a problem would be built on mathematical proofs of varying length. They’re quite delightful once you get the hang of them.
Have a Goal
It could be as vague as “getting an internship” or “preparing for a class”. Some users have target companies, and pratcice questions associated with them — Leetcode premium provides this information. I don’t think that’s bad, but companies grow and change their questions, and you don’t want to be the one who memorized comany X’s problems and, when interviewed by said company, wasn’t able to adapt to a slight variation of what they crammed. Instead, your practice should be scalable, pattern-oriented, and prepare you for unpredictability.
Have a Plan
This might be the most crucial step. Starting out the wrong way might lead to intimidation and abandon. It’s essential to follow a logical progression in topics and difficulty. For instance, basics such as strings and arrays are tackeld first, since they’re the building blocks for more advanced topics. This excellent article details a plan that I find very sensible (the author plans to post a breakdown of every stage). Difficulty levels are much easier to navigate: Leetcode labels problems by easy, medium and hard . Often, medium problems merge easy ones, so don’t underestimate the latter.
Language Doesn’t Matter. Not a Lot.
I used to fret about what’s the best language to learn and fully delve in. I was worried: in high school, I was taught an obsolete language, Pascal, and I wanted to ensure I’m learning the right one and not wasting my time. I soon learned this: it either depends, or , more commonly, doesn’t matter. It depends, in the event you have sepecific goals: developing iOS would imply Swift is a logical choice. Some companies have been known to have a preference — but, ask yourself if it’s worth it to commit to any company, as we all grow and change vision.
Essentially, there’s a general understanding that aside from a few niche languages, any of the more common ones will do. Here is a popularity index. Many job postings would list languages separated by slashes, indicating one or the other are satisfactory. You’ll hear this repeatedly: it’s the logic that matters most, then comes the command of the language. Personally, I’ve seen Java, C++ and Python being the prodominant picks for learners, job listings, and forums — it appears you can’t go wrong with these. Also, enough similarities exist that make your knowledge of one partially transferrable to another. I’ve met a woman who had learned a language in less that 10 days, using her understanding of another.
Have a Problem Solving System
As you progress, create a system for approaching a problem. Break it down, draw it, create modules, etc. Does the problem conceptually resemble another one you’ve covered? Would an algorithm like Greedy or Divide and Conquer be applicable? Express what needs to be done in English. Write pseudocode. Ease into the actual coding phase; a lot of what leads to it is indispensable, and interviewers want to see the way you build up to your solution.
Something that never fails me is talking to myself, as if I’m delivering an assignment at the end of a lesson. Sure, your housemates/family might find it odd, but they’ll get used to it. This helps me tremendously, particularly because I’m not a native English speaker and I completed high school in a different language. If unfamiliar terminology or notations came up, I have the empathy towards myself to take the time to research and comprehend it. You’d do that for a student of yours, so do it for yourself.
Be Mindful of Patterns
After a dozen problems, I started detecting patterns in problems. These could be as simple as knowing the Two Pointers technique is frequent for solving string problems, or having the intuition to create an extra iterator to keep track of a changing index. It’s a satisfying stage to get to. And it’s important because, starting out, one shouldn’t memorize problems: it’s unproductive, and doesn’t help developing problem solving skills. But beginners probably wouldn’t be able to come up with an approach with no prior exposure. So, be cognizant of the patterns.
You will get stuck — and, resolving such moments is of utmost euphoria! The concensus is that if you’re spending more than 10 minutes unable to develop a strategy, seek outside help. To get a nudge, use the “hints” section at the bottom of problem descriptions. The second best step, which I’d argue is a target skill for any problem solver, is to google your obstacles, and google them right. Use the right keywords, eliminate the fluff, and pinpoint the relevant answer.
When needing further help, it’s available for free in the “discussion” section, where talented users share approaches. Buying Leetcode premium grants you access the website-approved solutions. Whatever you do, seeing the full solution should be last resort. I’d recommend reading the title of the solution’s description, often containing key words as to which tools you can use.
Use print statements: they’re handy with understanding what’s going on inside a loop (even better with nested). Loops are cyclical, and nested ones are difficult to visualize in full. Seeing contents of a dictionary printed for every iteration goes a long way in answering “what does this do”. When submitting, print statements might cause a runtime error, so eventually they’re best deleted.
Find a Community
This falls under getting unstuck, and building belonging. Websites like Stack Overflow and Reddit have teeming communities dedicated to programming. Language-focused forums like r/learnpython, cplusplus.com and Python.org are a godsend — the latter is explicitly dedicated to open-source values, and to people. Learn to ask specific, well-formatted questions. List what you did and help others understand your thought processes.
I would also recommend online study groups: I found mine through a GHC community. This was quite easy to establish, since folks are eager to learn and productively compete. Discord has many channels for leetcoding. So, reach out to college friends, colleagues or online communities. You’re guaranteed a positive response. A one-on-one variation of group study is accountability buddies. You set a practice goal and commit. It’s also a wonderful quarantine antidote.
Help me reach more people: If you find this article useful, please consider giving “claps” 👏 at the left margin of the page (on desktop) or at the bottom (on mobile). You can do so up to 50 times by clicking continuously, a feature many don’t know about Medium! You’d help the story reach more learners, and give me insights on what topics I should write more about.