Hacker News new | past | comments | ask | show | jobs | submit login
Coding Interview Problems with Detailed Solutions, Test Cases, Program Analysis (hoanhan101.github.io)
327 points by hoanhan101 14 days ago | hide | past | web | favorite | 70 comments

Somewhat related: a while ago I went through a bunch of the "Cracking the Coding Interview" problems and completed them in Rust, whilst recording most of the coding for YouTube (until I got bored).

Here's the project: https://github.com/brndnmtthws/cracking-the-coding-interview...

Wow, that's awesome I was literally just looking for something exactly like this.

I have been prepping for almost 6 months now. I look at the stocks new hires get at my company and what my refreshers are. Companies seem to be relying on the fact, most people are too lazy to leetcode and will not give good refreshers. I have been with the company long enough that leaving and coming back atleast will add 600k to my earnings in the next 4 years. One thing however though I notice, that my coding speed has improved a lot by doing timed leetcode questions. I also look at the complexity of everything I write far more than I used to. Overall it looks like a win, win for me. The moment my company gave same level of stock as I would get in 2 years to a new college hire, I have decided to move. I have been with the company for more than 18 years. It is possible it is my company that does this. I hear goog refreshers are good.

Although I absolutely hate it, I interview every 1 or 2 years and use it as negotiation for refreshers. The only time I ever got a reasonable pay bump was by showing I had alternative offers. On the other hand, you have to also be willing to leave.

I like using the Blum Mental Hash as an interview question. As far as I can tell, it's not mentioned in any interview cram lists, and it's complex enough to see how candidates split up a problem.


That looks fun. Do you require them to know trivia or do you provide them with the definition and ask for an implementation?

I explain how it works first and then ask for an implementation. I look for sane code organization, correctness, and an awareness of Pythonic idioms if it's a Python heavy role.

It feels really easy? Or am I misunderstanding the algorithm/question?

It's not rocket science, no. I wanted something that could be done rather quickly, that would generate a fair amount of code, that wouldn't require any recursive tricks or discrete math. From there, I can usually look at their code and make a determination.

It pains me to see another Coding Interview preparation tool. It's such a sad situation in the current industry.

Students learn to game the system to get a high paying job. Students who care about what they are working on will painstakingly try to perfect their projects. They don't have time to game the system and therefore have a hard time getting a coveted job.

Companies want to hire "the best" so they usually hire someone who can ace the company's interview. People who can ace the company's interview are usually those who studied for it.

I recently took over a codebase from an ex-employee who went to Google. People were happy for him but I am so indignant. His code caused me hell. One production bug after another led me to eventually throw out all of his code. His code was written by somebody who did not care and his tests were useless. I'm pretty sure during his time at our company he was focused on leetcoding so he could get somewhere better. I wanted to reach out to him on LinkedIn to give him a piece of my mind hoping it may make him a more responsible engineer but I decided against it. I focused on fixing the features for the users because it was the right thing to do.

I want to work with people who care about the product they are working on. People who care about building great products are not solving coding interview problems.

Currently a junior in a reasonably well-regarded (and difficult) CS program, this is 100% how I feel. As a result of my genuine interest in the material being taught and desire to do well on course projects, I do not have the time or energy to be grinding Leetcode and HackerRank to the extent that I've read others do. Yet every company I apply to will not even speak to you unless you pass their brain-teaser-esque HackerRank problem, many of which are somewhat ambiguous and have typos in the problem statement. It's infuriating and seems like it only incentivizes the behavior you describe here.

I was interviewing with a company a year ago that had their own private tests on something like hackerrank. My code met the stated requirements and all of the publicly posted test cases. But, I failed a private test for which they would give me none of 1)the input 2)the expected result and 3) outpput of the program. I would have loved to have debugged it and fixed it, but said fuck it. Ifbthis is how they are in a preinterview, not a place I want to work. So, I told them to get bent when they declined to bring me on site because I couldnt pass their test. Told the recruiter what happened, and he was like "that's fucked up".

Coding challenges are one thing, but you better have precise specs and actually give the candidates enough info to work on a tractable solution.

I'm sorry you feel this way. The best advice I can come up with is, either find a product space you care deeply about and see how far you can take it or swim with the wave and start preparing for coding interviews.

Interestingly, the only places I've interviewed with that deviated from the typical SV coding challenge interview have been the national labs (JPL, LANL, Sandia, etc.). The questions they asked were much more focused on my interests as well as evaluating my general software engineering skills. I did an internship at one of them last year and it looks like I might be headed back there this summer too. Hoping I don't get locked into the national labs scene permanently.

Sometime, "good candidates" shop around for more offers. It is not always clear any greater effort would actually yield better candidates. Where I work, the entire interview process is just a filter to remove the absolute worst. Then it is a game of luck - whether we can meet the insane demand of the one we liked and whether we are just another "offer" for them to negotiate elsewhere.

I think if companies are better at firing/managing mediocre employees, we wouldn't have so much bad apples trying to make their way in.

Part of the problem is the scarcity of engineers. There is an entire swath of great people, by that I mean decent folks who would be great at what-we-do, entirely avoiding the field because of per-conceived notions or some stigma or the other. If there a better and bigger pool of candidates, the bad ones will naturally leave the field.

To your last point, it's actually quite hard to break into this field because of these kinds of interviews. That, and every SWE job posting having a Sr. Prefix.

On the other hand, the current interviewing trend generates a steady supply of nifty, bite-sized problems to solve for fun.

I keep a "practice" repo on Github, where I put my solutions. Often, for an extra challenge, I'll prove the solutions correct or try to write clear explanations of how to solve the problems from scratch. (Proving something helps me to see the hidden structure upon which my intuition rests. Explaining something helps me to lock it in my head.)

Over the years, I have learned a lot from this practice and have built up a repo that serves to keep my memory fresh. Here are some fun examples:




So, in at least one respect, I like the obsession with interview problems :)

Nice. That first one is a personal favorite.

Do you do "competitive programming"? You might like it. There's contests of various flavors out there to get a bunch of problems from.

Random recommendation: "Looking for a Challenge", a _beautiful_ in every way book of problems. Seriously check it out. Can almost guarantee you'll love it judging from those problems you linked.

Google Foobar is fun if you can get your way in. The codejam problems are nice (skip kickstarter mostly). codechef.com and codeforces.com have generally good problems (and fun contests if you're into that aspect).

Thanks for the great book recommendation! I just ordered a copy from a bookstore in Poland. I am eagerly awaiting its arrival.

I don't really do competitive programming, but I enjoy the problems. Thanks for recommending some great new sources to check out!

This is something I've been going through for the past 2 months. The last few years I've been contracting with IGOs and VCs. Going through interview rounds with medium-large companies and some FAANG has had me purely doing algorithm problems instead of actually building or writing. But hey at least I can find the common elements between two graphs and return their values as a lowercase string.

Something happened between 2012 and today where you could get by one referral and a conversation with a tech lead. Maybe it's the influx or new grads entering the field.

What's IGO?

Intergovernmental Organization.

Now zoom back one level. Most of the jobs (not all!) are doing something pointless like increasing advertising revenue.

Maybe that's the point. Make the wall so tall and hard to climb that candidates are convinced what's on the other side must be worthwhile.

I'd say 99% of the job postings FAANG recruiters email me about sound brain meltingly dull.

What's the alternative? Useless behavioral interviews? Sit-down exams and outdated certifications? Agents, middlemen and other leechers? Getting hired only through connections or favors? That's how every other industry in the world works, and I am thankful that the software industry has a somewhat-sane interview process based on actual skill.

Crazy idea: sit someone down to an IDE and let them code.

I’ve done this as an interviewer. I’ve created a fairly simple skeletal project with failing unit tests. The coding part of the interview was to make the tests pass by writing the code. It was a pair coding exercise.

I had a company give me a Wonderlic test. If the coding interview algorithm game is the standard at this point, maybe we should be thankful.

I want to work with people who care about the product they are working on. People who care about building great products are not solving coding interview problems.

Unless you are a founder or have significant equity, why should you “care about the product you are working on” more than enough to get a paycheck? It’s naive to think that a profit seeking employer cares about you. If you got hit by a bus tomorrow, they would send flowers to your funeral and have an open req for your position before you are buried.

While you may want to work with people who care about building great products, most people go to work every day for a paycheck. Why wouldn’t I optimize to play the game in a manner that increases the amount of my paycheck?

That being said, I personally don’t live on the west coast, have no desire to live on the west coast, and haven’t had an algorithm style interview in over 20 years when I was applying for a job doing low level cross platform C. I did get the job and they did need someone with algorithmic knowledge.

It is the environment the industry has created.

I'm terrible at code trivia type stuff. My Jr dev job I got from a company that asked me to build something for them. It wasn't big or useful, but it gave me a chance to show my thought process and there we go I got hired.

Since then it has been a great ride as I fix things as I make enhancements (I try to leave wherever I work a better place) and even built an application that complements their main application (customers love it).

Meanwhile some friends I talked to say they can't find good people .... but their interviews are all trees, and trivia and 'typical' interview type stuff that doesn't really demonstrate being a responsible coder, the ability to work independently, or just common sense....

Pretty sure I'm going to have to dive into that stuff if I ever decide to move on.

Why should he care about “being a good engineer” if all he has to do is reverse a binary tree on a whiteboard and make more money than he probably ever dreamed of?

> ... His code caused me hell. One production bug after another led me to eventually throw out all of his code. His code was written by somebody who did not care and his tests were useless. ...

We just need different coding interviews. Focus them on systems design, common pitfalls and 'fingertraps', good software engineering principles, etc. A "10x" software dev should definitely know her way around asymptotic O(n) analysis, she might also want to know about all sorts of exotic algorithms and data structures, but there's so much more to get educated about in this field, that could be tested for with relative ease.

I work for a FAANG and this is so true. My colleagues have through so much schooling and gaming in their careers that you hardly see anyone come up with new ideas. Working at these large tech companies feels like going back to school.

How’s this different from a school exam preparation tool? It won’t teach you the subject; and if it did then what’s the harm?

"The most damaging thing you learned in school wasn't something you learned in any specific class. It was learning to get good grades."


You shouldn't be studying to get good scores. You should be studying to learn and understand.

Grades is what will get you into university.

It isn't but you shouldn't use those either.

Assuming you are taking classes to learn things rather then get a job.

The coding interview in our industry reminds me of a question on Quora I got today. It asks if it is true that Richard Feynman only had a 125 IQ score. It is the case. And it makes me wonder how much good those interview questions are used to judge someone with a limited time. I know a few people in my company were let go after 6 months albeit they did fabulous with those interview questions.

IQ is hard to measure, and it isn’t really clear what it represents anyways. Metrics are always going to be incomplete, unlike in a litrpg.

Neat. I actually had a coding interview I got to skip because I'd already done the exact same question for another company, and had done my original work in Git+Github :)

Going through these and writing up solutions seems like a decent hobby project, applicable to a lot of situations.

Practicing for coding interviews are to FAANG companies what the SATs were for the Ivy League.

It's not about how smart you are or how well you will do. It's about how good you are at studying interview problems/the SAT. And even then it's a crap shoot if your admission reviewer/interviewer was in a good mood that day.

As much as it's suboptimal/unfair/whatever your objection is, your options are to not play the game (and miss out on the wealth of opportunity or cash) or to dive on in and accept reality.

some of these questions seem super easy, and then some of them have wording that seems impossibly hard to comprehend.

The fact that one can just ahead and cram for these problems should pretty much... severely downgrade, at least, their usefulness as hiring filters.

Everyone always says this, but the fact remains that it is a filter in the sense that not everyone can learn it, or retain it. People always complain that the techniques requested in an interview are not required for the job. I see it in a different sense. The jobs they ultimately qualify for do not require such skills.

There's now doubt that these tests serve as some kind of "a" filter.

The question is, whether they serve as a particularly good filter.

It’s a how-bad-you-want-it filter. Plus a bit of an IQ test (to recognize which solution applies—of course even more studying can help here, too).

It’s working as intended.

It’s a how-bad-you-want-it filter.

As long as that's how it's thought of - I can see the value.

I think people are in the habit that it does a lot more than that, though.

It's not so much that you can cram for this stuff (you can cram for anything, to some extent!) and more that this whole 'coding' interview and whiteboarding stuff has evolved into something that actively encourages cramming, and discourages professionalism and commitment to the actual work. It's indistinguishable from a cargo cult at this point.

FANG recruiters will even give and encourage these study aids to candidates before their interview.

Wouldn't you want people who care enough about their career to cram? That itself is a good signal. Cramming algorithms problems is difficult and succeeding shows grit. It also selects against sociopaths who BS their way through subjective personality interviews.

People who care enough about their career to cram falls into 2 groups pretty evenly:

1. People who care about building good products, leading to good careers.

2. People who care about their career for the sake of their careers. This group tends to focus on office politics.

Therefore, caring enough about their career to cram has not a signal for how much they will care about building great products.

Does anyone have insight on the extent to which interviews for ‘data scientist’ or ‘ML engineer’ roles involve Leetcode-esque or whiteboard coding exercises? What is the norm (if any) for assessing coding and subject matter competency for these sorts of roles?

It depends on the company and the role. In general, I would be prepared for some white boarding questions, although I've found they're generally "a little easier" than the ones the engineers whine about.

in golang

I think python is the most efficient language to use in interviews tbh. Functional languages might be better depending on the problem but you don't want people thinking you're a witch or something.

I learned enough Python for the interview questions specifically for this. Based on my (obviously anecdotal) experience, candidates I interview spend considerably less time on actual coding when using Python.

That being said, Scala makes design questions much easier thanks to its type system.

Python (or really any dynamic programming language) makes interviews a lot easier, however I have started asking more in-depth questions to make sure they actually understand Python and have done a little bit of research into the language and implementation.

I have noticed some colleges have been teaching more to the interview, so their grads can crush some problems in Python but fail when you ask them to implement a helper they were using. I am not talking about implementing a heap either, I am talking about merging objects.

there was a Google retrospective posted a long long time ago where someone cited data that people that use python do better. it's the reason I learned python.

I switched from Java to Python for coding interviews and it's well-worth it. I can solve problems a lot quicker due to the simpler syntax.

Agreed 100%. Switching from Java to Python because I grew tired of Java's verbosity.

I'd like to learn APL solely for interviews.

Wouldn’t work for a C++ position...

although most problem solutions seem pretty clear and understandable even for ppl not familiar with Golang

The new trend in SF/bay area seems to be companies you’re applying to preparing you _specifically_ for the questions they’ll ask. People realized no one memorizes one specific search algorithm or puzzle, so they now tell you, before the interview, that you’ll be asked problems A, B and C.

Not “algorithm problems” or “search” - “we’ll ask you to revert a doubly linked list”.

It’s bizarre.

Where have you seen that? The most I've been given is a general interview prep guide about how to prepare for an on-site.

2 “FAANG” companies and another one of the top big tech ones. One had a recruiter calling and literally listing all the questions they “could ask”, coding, architecture and all. They asked all of them.

I don't think it's the companies themselves as much as the recruiters. I've had recruiters pump me for info on the specifics of the question asked, and I obliged. I was younger and naive, and... didn't understand what they were doing. Not until later, when the reverse happened to me - I was given "potential" questions to prep for (which... I already knew answers to because it was my regular day job for) that I understood why I'd been asked about that stuff before.

You are implying that FAANG recruiters are doing this without the knowledge or consent of the hiring team, which is ridiculous.

If recruiters are incentivized by a metric of how many candidates get through the process, why wouldn’t they do that without the consent of the hiring team?

External recruiters do that all of the time. I worked with the same recruiter when I was trying to get a job and when I was hiring through him. I knew he prepped candidates so I had to have a different set of interview questions and different coding interview tests (with an IDE on a computer).

I know of one company where the hiring manager had all of the candidates do a merge sort on the board. He used the same interview question for years. All of the recruiters knew what to prep their candidates for.

Couldn't that have been a coincidence? or good research by the specific recruiter? or a recruiter that is cheating at his/her job?

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact