How should I go about doing leetcode questions?
March 4, 2022 7:07 AM Subscribe
First, I don't really like these questions. I think they're dumb and don't really say much about anyone other than they know some specific knowledge about CS. I feel that they just prove you're good at solving trick problems.
Nonetheless, they are unavoidable in software. A lot of companies ask about these. So, I'm wondering.
What's the key thing to solve them? I've always had my troubles with them, but I really shouldn't.
I mean, I can do reinforcement learning, think about how markov chain monte carlo methods work, and other statistics related stuff. That is by far a more difficult thing than what most of these questions ask.
Nonetheless, they are unavoidable in software. A lot of companies ask about these. So, I'm wondering.
What's the key thing to solve them? I've always had my troubles with them, but I really shouldn't.
I mean, I can do reinforcement learning, think about how markov chain monte carlo methods work, and other statistics related stuff. That is by far a more difficult thing than what most of these questions ask.
I'd push back against the assertion that reinforcement learning and so on is harder that LeetCode. LeetCode is about algorithms, which is a reasonably "difficult" area built up by a lot of smart people who defined it.
Are you coming from a statistics background rather than CS? If so, I would start by viewing some introductory algorithms lectures on YouTube or Coursera or whatever. Get the CLRS textbook and start working through some chapters and problems. It doesn't matter which ones -- the key is to get yourself in the problem solving mindset. Then get Cracking the Coding Interview and work through it systematically. That will give you a foundation upon which you can start to tackle LeetCode.
posted by redlines at 7:42 AM on March 4, 2022
Are you coming from a statistics background rather than CS? If so, I would start by viewing some introductory algorithms lectures on YouTube or Coursera or whatever. Get the CLRS textbook and start working through some chapters and problems. It doesn't matter which ones -- the key is to get yourself in the problem solving mindset. Then get Cracking the Coding Interview and work through it systematically. That will give you a foundation upon which you can start to tackle LeetCode.
posted by redlines at 7:42 AM on March 4, 2022
What parts of them do you find difficult? I just finished a bootcamp so we did a lot of leetcode practice.
The thing that helped me best was resisting the urge to just jump into coding the problem - even if I felt like I knew what to do - and take the time to write out pseudocode first. It will help clarify if there are any edge cases or tricky parts of the problem to ask about.
They're not just seeing if you can solve the problem, they're seeing whether you can sequentially talk through a new method, ask questions, and explain your solution clearly. They want to see how you communicate about a problem just as much as solving it.
posted by nakedmolerats at 7:52 AM on March 4, 2022 [1 favorite]
The thing that helped me best was resisting the urge to just jump into coding the problem - even if I felt like I knew what to do - and take the time to write out pseudocode first. It will help clarify if there are any edge cases or tricky parts of the problem to ask about.
They're not just seeing if you can solve the problem, they're seeing whether you can sequentially talk through a new method, ask questions, and explain your solution clearly. They want to see how you communicate about a problem just as much as solving it.
posted by nakedmolerats at 7:52 AM on March 4, 2022 [1 favorite]
A couple ideas:
posted by Nonsteroidal Anti-Inflammatory Drug at 8:14 AM on March 4, 2022 [4 favorites]
- https://algo.monster/ runs you through a pretty short quiz to see what you know / don't know, and then helps you learn the patterns of the questions.
- A good discussion about the patterns: The DEFINITIVE way on how to LeetCode properly. (Hint: You are most likely doing it wrong!)
- Finally, here's a job board for companies that have interviews that likely won't use leetcode: https://www.nowhiteboard.org/
posted by Nonsteroidal Anti-Inflammatory Drug at 8:14 AM on March 4, 2022 [4 favorites]
Response by poster: No, I'm not from a statistics background, I come from a CS background. I've done leetcode before and interviews as well, I know the underlying concepts these questions are asking about. I just get very nervous when I have to solve these questions.
Yes, I'm aware of CLRS, I've read parts of it as well as Cracking the Coding Interview.
posted by Tarsonis10 at 8:42 AM on March 4, 2022
Yes, I'm aware of CLRS, I've read parts of it as well as Cracking the Coding Interview.
posted by Tarsonis10 at 8:42 AM on March 4, 2022
Oh man, I did some leetcode this summer to prep for interviews, it was lame. The technique that worked well for me is as follows:
* Identify a leetcode problem to solve.
* Think about how to solve it for ten minutes (do not write code! just think of your approach and write out the algorithm in words) .
* If at the end of ten minutes I had a viable strategy, great, go ahead and write the code.
* If not, go to the solutions tab for the problem and read several solutions in my language. For more popular problems I would also watch youtube videos of people walking through their algorithm.
* Choose one of the algorithms, write it out myself, and them implement it in code.
This addresses one of the core problems with leetcode problems - if you simply do not know about the existence of a certain technique or algorithm or principle, you are unlikely to get anywhere by spending an hour having a terrible time failing to solve the problem. The goal of the leetcode problem is not to solve the problem, but to give you a doorway into learning a bunch of building blocks for solving other leetcode-like problems.
posted by nevernines at 9:09 AM on March 4, 2022 [4 favorites]
* Identify a leetcode problem to solve.
* Think about how to solve it for ten minutes (do not write code! just think of your approach and write out the algorithm in words) .
* If at the end of ten minutes I had a viable strategy, great, go ahead and write the code.
* If not, go to the solutions tab for the problem and read several solutions in my language. For more popular problems I would also watch youtube videos of people walking through their algorithm.
* Choose one of the algorithms, write it out myself, and them implement it in code.
This addresses one of the core problems with leetcode problems - if you simply do not know about the existence of a certain technique or algorithm or principle, you are unlikely to get anywhere by spending an hour having a terrible time failing to solve the problem. The goal of the leetcode problem is not to solve the problem, but to give you a doorway into learning a bunch of building blocks for solving other leetcode-like problems.
posted by nevernines at 9:09 AM on March 4, 2022 [4 favorites]
I think my advice still stands even if you have a CS background and are familiar with algorithms. One forgets over time.
posted by redlines at 9:19 AM on March 4, 2022 [1 favorite]
posted by redlines at 9:19 AM on March 4, 2022 [1 favorite]
Just saw your new comment - I'm curious if you primarily are having difficulty solving leetcodes when practicing, or when live interviewing? If the latter, some things to think about:
* If you can't solve a problem in a live interview that you can in a similar amount of time while practicing, you may need to figure out how to step out of the way of the part of your mind that knows how to solve the problem. I love Alexander Technique for this, but lots of mindfulness practices could work.
* What language are you working in? The best language for you for leetcode problems may be different than the best one for you for like, personal projects. If the kinds of things that trip you up and escalate your anxiety during the interview have to do w/ library imports, lack of autocomplete, static typing errors, ect, it could be worth switching to something else. Languages where it is very easy to do string manipulation in particular are good.
* Cultivate a sense of play around both practicing and interviewing. You already know this stuff doesn't really matter, and your interviewer does too. Think about it like a playdate where you get to show up, forget about your real work problems for an hour, and play around with a clearly defined problem with a tight feedback loop and sometimes a new friend who you can talk to about it.
posted by nevernines at 9:28 AM on March 4, 2022
* If you can't solve a problem in a live interview that you can in a similar amount of time while practicing, you may need to figure out how to step out of the way of the part of your mind that knows how to solve the problem. I love Alexander Technique for this, but lots of mindfulness practices could work.
* What language are you working in? The best language for you for leetcode problems may be different than the best one for you for like, personal projects. If the kinds of things that trip you up and escalate your anxiety during the interview have to do w/ library imports, lack of autocomplete, static typing errors, ect, it could be worth switching to something else. Languages where it is very easy to do string manipulation in particular are good.
* Cultivate a sense of play around both practicing and interviewing. You already know this stuff doesn't really matter, and your interviewer does too. Think about it like a playdate where you get to show up, forget about your real work problems for an hour, and play around with a clearly defined problem with a tight feedback loop and sometimes a new friend who you can talk to about it.
posted by nevernines at 9:28 AM on March 4, 2022
The answer to "What's the key thing to solve them?" is absolutely "it depends".
There really isn't enough information here to give advice. Everyone's learning and study style is different, and we're lacking specifics about exactly where you think you're having problems (speed, correctness, just can't figure out how to solve them by brute force, something else?).
posted by caek at 9:32 AM on March 4, 2022
There really isn't enough information here to give advice. Everyone's learning and study style is different, and we're lacking specifics about exactly where you think you're having problems (speed, correctness, just can't figure out how to solve them by brute force, something else?).
posted by caek at 9:32 AM on March 4, 2022
Best answer: I like Interview Cake for providing a program of structured practice to move through the questions and to play the role that an interviewer might play in a real situation, giving hints and asking clarifying questions.
Also, here's the thing about this:
First, I don't really like these questions. I think they're dumb and don't really say much about anyone other than they know some specific knowledge about CS. I feel that they just prove you're good at solving trick problems.
You're right. Of course you're right. Nevertheless, I suggest you try, as much as possible, to stop dwelling on this. When I'm going out for interviews, my main obstacle is precisely this sense that "this is stupid and I don't want to do it." You don't want to find yourself getting so annoyed that you're like a former coworker of mine who was unable to stop himself from asking in an interview if generating a fibbonacci sequence was a common problem for the business.
posted by Ragged Richard at 9:46 AM on March 4, 2022 [2 favorites]
Also, here's the thing about this:
First, I don't really like these questions. I think they're dumb and don't really say much about anyone other than they know some specific knowledge about CS. I feel that they just prove you're good at solving trick problems.
You're right. Of course you're right. Nevertheless, I suggest you try, as much as possible, to stop dwelling on this. When I'm going out for interviews, my main obstacle is precisely this sense that "this is stupid and I don't want to do it." You don't want to find yourself getting so annoyed that you're like a former coworker of mine who was unable to stop himself from asking in an interview if generating a fibbonacci sequence was a common problem for the business.
posted by Ragged Richard at 9:46 AM on March 4, 2022 [2 favorites]
Best answer: I'm a big fan of Cracking the Coding Interview moreso than LeetCode. Remember to write stuff down before you start typing. I'd say do them entirely by hand, but now interviews have moved substantially online, so the typing practice is less counterproductive than it used to be.
My background is actually in pure math, specifically algebraic combinatorics. I find that having done combinatorics makes be better than average at these sorts of coding questions. So... my slightly off the wall suggestion is to bust out your discrete math book and do a bunch of "count how many X there are" questions and discrete probability questions because, at least for me, it's the same muscle. A really common term in the math world for the sort of question you're looking for is "12-fold way".
posted by hoyland at 10:04 AM on March 4, 2022 [1 favorite]
My background is actually in pure math, specifically algebraic combinatorics. I find that having done combinatorics makes be better than average at these sorts of coding questions. So... my slightly off the wall suggestion is to bust out your discrete math book and do a bunch of "count how many X there are" questions and discrete probability questions because, at least for me, it's the same muscle. A really common term in the math world for the sort of question you're looking for is "12-fold way".
posted by hoyland at 10:04 AM on March 4, 2022 [1 favorite]
Response by poster: Just saw your new comment - I'm curious if you primarily are having difficulty solving leetcodes when practicing, or when live interviewing? If the latter, some things to think about
Both, with leetcode practice I get frustrated when I can't solve a particular problem, it makes me feel stupid. In live interviews, I have ended up panicking and messing up, even though looking back at the questions, they were never really anything I couldn't solve if I wasn't getting nervous about it.
posted by Tarsonis10 at 10:06 AM on March 4, 2022 [1 favorite]
Both, with leetcode practice I get frustrated when I can't solve a particular problem, it makes me feel stupid. In live interviews, I have ended up panicking and messing up, even though looking back at the questions, they were never really anything I couldn't solve if I wasn't getting nervous about it.
posted by Tarsonis10 at 10:06 AM on March 4, 2022 [1 favorite]
Sounds like the only way through is de-sensitization... keep doing them until you're familiar with them so you're no longer nervous.
posted by kschang at 10:17 AM on March 4, 2022
posted by kschang at 10:17 AM on March 4, 2022
From the maths side: this is about learning patterns so you can turn problems in front of you into things you already know how to solve.
It looks and smells like a pissing contest, but there's no other way than graft to have a sense of the algorithm you might apply and what performance constraints make one approach better than another. Write a lot of code to throw away, you will learn from it.
posted by k3ninho at 1:22 PM on March 4, 2022 [1 favorite]
It looks and smells like a pissing contest, but there's no other way than graft to have a sense of the algorithm you might apply and what performance constraints make one approach better than another. Write a lot of code to throw away, you will learn from it.
posted by k3ninho at 1:22 PM on March 4, 2022 [1 favorite]
If you know the answers to the questions but the issue is that you panic during interviews, then I think more practice can help but you might also want to address this as interview anxiety. Doing practice interviews (not just coding questions) can help. A mindfulness practice can also teach you to just observe the feelings rather than being overwhelmed by them. You could also try therapy--it's not just for dealing with deeper issues, you can look for a therapist who does CBT and mindfulness work and specify that you want to work on this one problem for a few sessions.
posted by Anonymous at 10:01 AM on March 7, 2022
posted by Anonymous at 10:01 AM on March 7, 2022
This thread is closed to new comments.
posted by michaelh at 7:23 AM on March 4, 2022