
A guide to learning algorithms through LeetCode - VitalyAnkh
https://github.com/labuladong/fucking-algorithm/tree/english
======
digianarchist
It's becoming obvious to me that my time is better spent learning to solve
these riddles rather than actually becoming a better developer. I have a job
search coming up at the end of the year and whilst I've managed to largely
avoid companies that ask this type of question, I believe it's seriously
constraining my career.

I can't speak for everyone but the whiteboard interview has prevented me from
leaving jobs earlier, moving jobs more frequently and left me avoiding certain
companies altogether.

~~~
logicslave12
I was working on a “startup”/kinda just unemployed for two years. I studied
leetcode hard, and got hired into a 300k a year job at FAANG. I know nothing
about testing, git, software process, roll outs, dev ops, etc. I barely know
how to do software engineering. What an idiotic hiring process.

~~~
PragmaticPulp
Interviews are only partially about testing your body of experience. They're
also supposed to test your aptitude and ability to grow in the future.

If you were capable of studying Leetcode so hard that you mastered the
interview process at one of the most selective software companies in the world
in only a few months, it's not much of a stretch to imagine that you could
apply that same aptitude, ambition, and ability to learn quickly toward
picking up the basics of git, dev ops, and so on.

Arguably, this is one of the benefits of Leetcode-style interviews. They focus
on core software engineering aptitude, while not arbitrarily excluding people
because they didn't use the right VCS at their last job.

~~~
zerr
Err, but why do you have to prove it for every next job?...

In reality, it's a legal way for:

1\. Ageism - not many seniors are desperate enough or have a free time for
Competitive Programming preps.

2\. Making switching jobs harder - for every next job one has to prepare
again, because nobody is using Competitive Programming stuff during real work,
so you forget.

Keep in mind that CP != CS.

And CP is not everyone's cup of tea. It is a separate discipline/subject with
its own trivia knowledge & tricks. CP uses Computer Science the same way as
e.g. Physics or Biology use Math.

~~~
jkcorrea
#2 doesn't make sense, though: If I'm company B, trying to poach from company
A, it would be in my best interest to make the leap to applying/interviewing
less difficult, not more for employee's of company A.

Unless you're implying a set of companies are all in league with each other to
reduce churn/competition for talent

~~~
kkkiiiooo
> Unless you're implying a set of companies are all in league with each other
> to reduce churn/competition for talent

This is a proven reality, and has been out in the open for a long time.

~~~
BurningFrog
Then a few links to those proofs should be easy to produce?

~~~
bretpiatt
On this same thread
[https://news.ycombinator.com/item?id=24182126](https://news.ycombinator.com/item?id=24182126)

~~~
BurningFrog
Yeah, I know about that one. Wondered if anything new had come to light.

This was 10 years ago and involved 8 companies.

Concluding from one crime that they all do it, and that's just what those
people are like, you can't trust them etc, is an impulse we all do well to
resist.

Of course, concluding that nothing like this will ever happen again is also
naive. The incentive to cooperate is certainly still there.

My impression is that since the 2010 case, wages have gone up dramatically in
that class of companies. There are also more big companies with owners who
aren't pals from before. I think. Just guessing, relly.

------
bradlys
Gosh, I don’t enjoy that there is so much competition in this space. I can’t
compete against people who essentially seem to have no life or other interests
than getting job at Big N (or enjoy competitive programming).

It feels like this culture has ramped up in the last 5-10 years. When I
started interviewing, the questions were easier. It feels like they’ve gotten
more difficult - or at least the answer the interviewer wants is less
attainable.

And I feel like I know why - go look at the leetcode discussion forums.
There’s almost always some post at the top saying, “I did 1000 problems and
won’t stop. I got accepted/rejected and learned so much. Believe.” From the
outside and inside, it looks like a cult. I feel like these folks are just
making it worse for everyone.

Maybe I am just bitter because I’ve passed every mock interview I’ve done but
I can’t get an offer from Big N still. Startups are the worst as a non-
founder/non-executive.

~~~
PragmaticPulp
> I can’t compete against people who essentially seem to have no life or other
> interests than getting job at Big N (or enjoy competitive programming).

Interview prep doesn't need to be a grind. One of the nice things about
Leetcode is that the problems are bite-sized. You can do one or two per day on
your lunch break and make a lot of progress in a matter of months, or even
weeks.

Don't approach it like a cram session before your interviews. That doesn't
work unless maybe you're a new college grad with no other obligations.

> go look at the leetcode discussion forums. There’s almost always some post
> at the top saying, “I did 1000 problems and won’t stop.

Obviously the Leetcode forums are going to be a hotbed of discussion about
Leetcode. You have to keep in mind that many of those people are entry-level
developers treating this as an extension of their education. For them, it's
basically a miracle that a mostly-free website lets them practice for
interviews for $200K-300K+ career paths from the comfort of their web browser.
Compare that to just about any other high-paying industry, where getting the
right education, credentials, certifications, and test results will take years
of your life and potentially hundreds of thousands of dollars of post-
secondary education. We really have the easy end of this deal.

Don't let the total number of Leetcode questions overwhelm or discourage you.
It shouldn't be approached as a cram session before the interview. It should
be approached as a consistent habit or practice over a longer period of time.

If you just don't want to do any Leetcode or whiteboard interviews, that's
fine too! There are plenty of jobs out there that won't require any of that.

However, you can't have it both ways: Big N salaries come with a high barrier
to entry. All things considered, spending 50-100 hours of your free time
solving problems on a free website at your leisure is really a small price to
pay.

~~~
bradlys
> All things considered, spending 50-100 hours of your free time solving
> problems on a free website at your leisure is really a small price to pay.

The problem is - it's not 50-100 hours for most candidates to pass. I've done
well past 400 hours of interview prep and never received an offer from Big N.
I tried the consistent 1-hour or so a day for months thing - it isn't
guaranteed either. Want to emphasize this point to - it isn't like I can't do
the problems. I've solved most any problem I'm given - it's that it just
doesn't fucking matter. Whatever bias the person has is what they will
evaluate on - the problem solving is merely a formality.

~~~
nulptr
I don't think it's just about solving the problem.

It's also about: \- how you convinced yourself and the interviewer that your
solution was correct (essentially an informal proof of your code)

    
    
      - how you test your code after you finish coding
    
      - what clarifying questions you asked to tease out a concrete question
    
      - what edge cases you thought of and how you handled them
    
      - how you handle bugs if they appear in the code
    
      - what solutions you presented and what their tradeoffs were, and why you decided to use a particular solution
    
      - whether your code was idiomatic
    
      - whether you used clean abstractions
    
      - maybe also comments and variable naming
    
    

... and probably others I'm missing.

I don't deny that interviewers have their biases, but I would hope that your
interview performance is the major factor in whether you received an offer.
There are plenty of people at Google and Facebook who haven't majored in CS at
a top school.

~~~
noema
From talking to some people who give out these interviews, most of those
points really don't matter at all. What matters is A) getting a correct
solution and B) being able to explain how you arrived at the solution. Tests,
idiomatic code, clean design, etc are not expected and will inevitably waste
precious time. Besides, the very nature of the interview (using a walled-off
in-browser pseudo-IDE) restricts you from actually writing best-practice code.

~~~
SerialOwl
How do you expect to convince the interviewer that your solution was correct
without tests? How can you debug your code properly if you end up with a
spaghetti mess instead of using a clean design?

~~~
noema
Testing and debugging vary from site to site. Most of the ones I've used run
your code against a hidden suite of tests to check all possible edge cases.
This would otherwise take up a very non-trivial amount of time in the session.
Actual debugging is also not possible on all of the sites -- usually the most
you can do is litter your code with logs, which is far from a clean design.

------
agentultra
I find this little sub-industry building up around, “the coding interview,” to
be highly strange.

Where are the papers that correlate this niche, specialized skill to general
job performance and productivity?

I get that at certain problem domains the asymptotic complexity becomes a
baseline for performance so I’m not against testing people’s knowledge where
it’s appropriate. But is it really the dominating skill?

Reading some of the comments of people who went through the pipeline of this
cottage industry, it sounds like it’s not even useful after you get hired. In
fact optimizing for it to get through the interview sounds like a bad idea!
Imagine landing the job and having no other skills.

I’m curious how these algo expert/monster/crushing the interview businesses
survive and perpetuate this highly competitive environment.

~~~
PragmaticPulp
> Where are the papers that correlate this niche, specialized skill to general
> job performance and productivity?

I would love to read this research if it existed in the public domain.
However, much of this comes down to trade secrets and business practices. It's
also not very amenable to controlled studies.

Practically speaking, these companies have a lot at stake in their hiring
process. It's strange that so many people are convinced that the Big N
companies are shooting themselves in the foot or otherwise making poor
decisions with these interview processes.

Leetcode-style interviews might not have supporting research in the public
domain, but absence of evidence is not evidence of absence. That is, just
because the research doesn't exist doesn't mean that the Leetcode interviews
are bad or worse than the alternatives.

Even if companies did eliminate Leetcode-style interviews, they have to
replace it with some other alternative. Most of these criticisms fail to
suggest actual replacement interview processes.

~~~
masterphilo
On your last point, the best alternative I've seen is take-home projects where
it would take less than a week to complete. The interviewer is free to frame a
problem in a way that allows the engineer to apply their real-world experience
and show their fit for the job. It removes all the variables around interview
stress/anxiety and as a result is a better (but not perfect) indication of
their performance.

~~~
PragmaticPulp
> On your last point, the best alternative I've seen is take-home projects
> where it would take less than a week to complete.

Ironically, take-home interviews are another contentious topic on HN and other
internet message boards. The common complaint is that people don't want to
invest much of their personal time into interviewing for companies.

~~~
extra_rice
I wonder which takes more time, take home tests or LeetCode grind...

~~~
azemetre
If I were interviewing I'd take a LeetCode over take homes any day of the
week. Preparing for LeetCode prepares you for nearly 70% of the jobs you will
likely interview at.

Whereas with take homes the amount of time doing say 12-take homes can easily
be too much. You end up in this weird positions where you can only devote so
much time for certain take homes but with the LC & System Design you can at
least prepare once and hit up a bunch of companies.

------
pcestrada
Can you imagine having to learn all this just to make a connection to a
database, process some data, and then persist it somewhere?

~~~
PragmaticPulp
The popular sentiment on computer science knowledge has done a complete 180 in
the past several years.

Not that long ago, it was popular to complain that junior SWEs didn't really
understand the algorithms, the data structures, and what was going on behind
the scenes. The complaint was that they were just copy and pasting from
internet searches until things sort of worked on their machine, but they
couldn't recognize when an O(n^2) solution was going to work on their local
n=10 test set but bring down the main website.

Now that knowledge of CS fundamentals has become valued in interviews, the
pendulum has swung the opposite way. We have more free resources than ever
before to practice and study CS fundamentals, algorithmic challenges, and even
practice your interview skills. It's never been easier for a junior SWE to sit
down, put in the effort, and work their way into a $200-300K job with
sufficient dedication. Yet people never tire of complaining about Leetcode or
having to understand CS fundamentals online.

Personally, I've never met anyone who was good at Leetcode yet produced bad
code in production. I'm sure there's someone out there who knows a guy who
knows a guy who can somehow ace Leetcode but can't write an efficient website
backend, but it's not the norm.

~~~
bcrosby95
> Personally, I've never met anyone who was good at Leetcode yet produced bad
> code in production. I'm sure there's someone out there who knows a guy who
> knows a guy who can somehow ace Leetcode but can't write an efficient
> website backend, but it's not the norm.

Weird. Ability to leetcode doesn't mean you know what is happening in e.g. an
RDBMS. We've had people good at leetcode write a single query to delete
hundreds of millions of records in a table with billions of records that was
being constantly updated by the live website. Needless to say it didn't go
over well. Ability to leetcode doesn't give you any knowledge that doing so
might be a bad idea.

~~~
xfer
You can learn how to use some function to call into a database and study its
behaviour, if you can grind leetcode and solve problems.

It's a good enough filter, the alternative is either way more costly or way
worse(if you have seen "interviewing" which are just thinly veiled nepotism).

------
OnionBlender
A good free algorithms book is [http://algorithms.wtf](http://algorithms.wtf)
(by Jeff Erickson)

~~~
unemphysbro
I took his class way back in 2010.

Challenging but fun.

------
doc_gunthrop
All the items are taken from Leetcode problems, but for the vast majority of
them the author (labuladong) does not give attribution.

There should at least be a link to the related Leetcode problem for each
section.

------
wisecoder
16+ years of experience and won several awards and designed multiple highly
scalable systems in retail. Still cannot get into faang. These coding
interviews gate keeping me..

~~~
dkarbayev
9 years of experience, used LeetCode for preparation for two months (solved
around 200 mostly medium problems) and got an offer from FAANG. Coding
challenges at FB and G are not that hard nowadays.

------
paulcarroty
Found in my bookmarks: [https://leetfree.com/](https://leetfree.com/)

Not sure if all quizzes are original, but some of them looks interesting.

~~~
fizixer
Can anyone explain/interpret what leetfree.com is saying here?

> ... don't try to solve it with online judge ...

> ... Try to learn from the solutions we provided as quickly as possible ...

> ... Interviewers only care about your WhiteBoard communication skills ...

Are they implying that rote memorization (memorize all problems and their
solutions) is the best/easiest way to do the interviews?

If yes, wouldn't that trip you up the moment you're asked something
new/original?

If no, what are they saying? Is the best leetcode stuff paywalled and they're
providing a free version?

what's the latest on step-by-step most effective way to get ready for standard
coding interviews?

Context: I'm trying to get back into this after many years. I've used leetcode
in the past but don't remember anything about online judge.

~~~
hackermailman
Online judge is competitive programming like
[https://open.kattis.com/](https://open.kattis.com/) or CodeWars or CodeForces
meaning a server that takes your source, compiles and runs it, tests if you
satisfied all the req of the challenge. There's books for this
[https://cpbook.net/#CP4content](https://cpbook.net/#CP4content) and despite
leetfree claims of being 'useless because no online judge in interview' there
is actually 2-3 judges sitting there in the interview performing the same
function, telling you if your code does not satisfy the problem requirements

------
tmpmov
Thanks for the write up and git book.

Related question: I’m curious if any has game-ified algorithm learning, sort
of like those old educational math games targeting certain grade levels.

Might be cool to make a point and click adventure centered around dynamic
programming or greedy algorithms.

~~~
ghj
There are plenty of competitive programming sites where you can grind rating
just like you would for MMR rating in video games.

For example CodeForces, AtCoder, TopCoder, and even LeetCode have rated
contests

~~~
tmpmov
Thanks ghj.

I was aware of top coder/leet code, though hadn't heard of code forces/at
coder.

For me the adventure game give a bit more concept linkage. Take Monkey Island,
I can remember how to reply to many of the sword fighting insults, or what was
needed to get pieces of eight via the cannon at the circus. There's something
to be said for linking problems via a memorable story, giving examples and
meaning from multiple angles helps retain the content over the dryness of
problem prompt/quick solve.

~~~
shahbaby
Usually when you try to combine education with gaming, the result is something
that's not very educational and not very fun.

~~~
barry-cotter
It can be done, see Dragonbox Elements or Dragonbox Algebra.

------
croh
I am a self taught programmer (python). I learned things because they required
to solve some problem. You face problem and then you find solution. I used to
solve puzzles in childhood for competative exams. But now as adult, it is very
difficult to connect with imaginary problems which you never deal in day to
day life. It makes me feel empty - learning something to just get a job.
Recently I picked up interest in OS because I started to notice my limit with
application programming. I learn to write comments and importance of git,
after working in startup where you keep wearning thousdands of hats daily and
forgot what code last week. And I feel this is very organic approach to learn.

Being on both sides of table, whenever I conduct interview I just ask simple
programs to do (mostly fizbuz) and try to gauge candidate passion by
understanding projects s/he worked and problems faced. If candidate passes
fizbuz, I believe s/he has basic understanding of logic. Other things can be
thought easily if candidate has passion.

I have friends in university who only talks about algos but can't write single
line of code (I am not blaming them, it is just their field doesn't require
intense coding. What i am trying to say here is, writing good code is like
craft. You need to write actual code to excel in craft. Solving leetcode
problem successfully doesn't imply you can write good code automatically).
Last time when I switched jobs, I studied couple of algos and now I forgot
them. I am again switching and thinking to start with leetcode. The biggest
problem in industry is hype. These days even small stupid IT shops are asking
for hackerrank test with full stack developer. Lot of focus is still on
memorization and hype.

------
bobblywobbles
Thank you for your guide. I do apologize in advance, but this tutorial, like
others, simply goes into the _what_ to do and doesn't explain the _why_.

Forever math will be about memorizing these "tricks" and not understanding it
intuitively - can someone please help offer some suggestions to me?

------
throw1234651234
What language should you grind leetcode in for FAANG? Or does it honestly not
matter. Like C# or Javascript, for example?

------
didip
Is there a list of companies that purposely not use Leetcode in their hiring?
Someone should make one.

~~~
digianarchist
[https://github.com/poteto/hiring-without-
whiteboards](https://github.com/poteto/hiring-without-whiteboards)

------
meow_mix
"fucking algorithms" such a good repo name tbh.

------
nickx720
This is really sweet. Thank you kind sir.

------
TACIXAT
This is really cool. What order are the chapters in? Seems intense to lead
with dynamic programming.

~~~
OnionBlender
I got really good at dynamic programming problems but then none of the
companies I interviewed with asked me a dynamic programming problem. These
were large tech companies and well funded startups. Perhaps it was just luck.

~~~
ummonk
I tell interviewees to practice some dynamic programming problems because
dynamic programming questions are the least intuitive, and it's good to be
prepared in case that's what you get asked.

For the same reason though, I think they make for terrible interview questions
- very much dependent on knowing a specific "trick" that doesn't actually come
up often in day to day coding.

~~~
extra_rice
DP as a paradigm is very interesting. From a high level view, one can
appreciate the essential concepts that make it work, with things like
memoization, optimal substructure, etc. It's also interesting how it relates
to shortest paths problems, and greedy algorithms.

However, as you said, actually trying to solve DP problems relies on knowing
the trick, and the tricks varies almost wildly from problem to problem.
They're unintuitive, and difficult to derive normally. The intuition you gain
from one of them could be entirely useless, or, worse, counterintuitive for
another. I personally think, they shouldn't be used for interviews because
being able to solve them seems to be more a matter of luck than actual
competence.

------
bohemian99
I haven't seen gitbook before, is this a common tool for documentation?

~~~
mettamage
Occasionally you see a gitbook on HN. It is mostly for well... books and
educational content.

------
Unklejoe
Edited to remove

~~~
pheug
Sorry for stating the obvious, but money is a pretty big reason to continue
doing leetcode style interviews. Most high paying employers ask them. Out of
curiosity, how much does your no-leetcode job pay? Is it at least $200k?

> If it comes down to it, maybe I’ll move into hardware design.

Hardware jobs generally pay less than SWE, you'll lose even further on the
monetary aspect.

------
ammanley
repo name is on point

------
Hackbraten
Why is the title censored?

As a European citizen, I absolutely don’t get it. Why can’t we say fuck on the
internet?

~~~
VitalyAnkh
Just personal preference. I made this title by myself other than censorship.
Anyway, “fuck” sounds a little rude.

------
person_of_color
Is this evidence of the 996 culture?

~~~
cheez
Looks more like tech interview culture.

------
Gummaluri
Temporary comment for following and future retrieval of this post.

~~~
Stratoscope
Imagine what would happen if everyone did that!

Some practical advice: HN has two ways for you to do this without cluttering
the discussion. You can simply upvote the post, or you can favorite it.

Both of these lists are available at the bottom of your profile page:

[https://news.ycombinator.com/user?id=Gummaluri](https://news.ycombinator.com/user?id=Gummaluri)

Be aware that favorites are public, while your list of upvoted posts or
comments is private. (View your profile page in an incognito window to see
what the public sees.)

