r/programming • • Sep 22 '20

Google engineer breaks down the problems he uses when doing technical interviews. Lots of advice on algorithms and programming.

https://alexgolec.dev/google-interview-questions-deconstructed-the-knights-dialer/
6.4k Upvotes

1.1k comments sorted by

View all comments

Show parent comments

15

u/KrypticAndroid Sep 22 '20

So what’s better?

81

u/serviscope_minor Sep 22 '20

So what’s better?

One of my favorite interview questions has at it's core an algorithm, but a simple one, and we start off with a quick discussion of the problem and how they might solve it. There's not a lot of choices on the algorithm because as I mentioned it's simple. This is mostly preamble so they have a mental framework for the next bit.

Then, we present them with some code which already implements it, except it's awful code, and has some bugs. Their goal is to refactor the code and make it clean. So they have to read and understand it, map it onto their understanding of the algorithm and make fixes. Many of the fixes are simple and can be done point-wise without fully understanding the code.

It's much more akin to day to day work of a software engineer. There's no trick to know or leap to make, it's just crappy code which needs fixing. It's telling for example if the candidates try to wing it, or add some basic tests, and whether their idea of "production code" is a profusion of classes.

18

u/[deleted] Sep 22 '20

I definitely agree that simple algorithms are better. Interviewers massively underestimate how hard something is when you don't already know the answer and have to come up with it on the fly. We "implement atoi" which seems to work quite well.

I like your refactoring idea - might steal it for the future. Although I did do one interview where they got me to write some code, and the feedback was that I didn't write enough tests. They didn't ask me to write any tests! So I think it does run the slight risk of candidates not knowing exactly what you want. I'll give it a go though!

2

u/BlueLionOctober Sep 23 '20

In most of the interviews I do I pick a question and I go into a room and I do it without knowing the answer and I time myself. I do that so I can get a gauge for how hard the problem is and what it's like to actually try to solve it. In some interviews where all my questions got banned because people post them online and I haven't had time to find a new one I may be solving the question at the same time as you. Implementing things is table stakes. Not being able to implement atoi would be weeded out in phone screens.

→ More replies (2)

1

u/serviscope_minor Sep 22 '20

Yeah, I mean we don't require tests, and some people do it with ad hoc testing. It's a much harder thing to get right without tests though, but the requirement is only to refactor it.

I don't think I've seen anyone succeed to a significant degree without tests.

15

u/decimated_napkin Sep 22 '20

This is a much better method in my estimation.

3

u/professor_jeffjeff Sep 23 '20

The only issue I have with this (I've done it) is that it's actually really surprisingly hard to intentionally write bad code, especially if you want it to be bad in a particular way.

→ More replies (2)

25

u/wy35 Sep 22 '20

I've heard Stripe does code pairs where you and the interviewer work together to fix a bug or implement a simple feature.

6

u/jlchauncey Sep 22 '20

We did this at rally. You came in and did a 2 hour long pairing session on the engineering floor. You had a set of problems you could choose from (game of life, check writing, maze building, and some others) and you and the other 2 engineers would work on it in any language you wanted.

it was by far the best part of the interview process because it told you a lot about how the interviewee worked and if they could handle our open office plan.

we actually had people turn us down because they couldnt work in our office env.

10

u/MishMiassh Sep 23 '20

Yeah, 100% turning down open floor code farms until that fad is gone.

→ More replies (6)

3

u/decimated_napkin Sep 22 '20

I think that's a really interesting idea.

2

u/MeggaMortY Sep 22 '20

My current job did the same. We got to debug a real broken unit-test in their code base, with the interviewer playing the suggestive pair-pgramming buddy. I didnt even solve the whole thing but it was clear we found the issue, how to solve it, and most importantly, that we can work together well.

1

u/foxh8er Sep 23 '20

They also don't interview anybody that hasn't passed a difficult interview process before (like Google or FB) so

12

u/LUV_2_BEAT_MY_MEAT Sep 22 '20

My company has you write a small simple program like fizzbuzz, then has you make changes/enhancements to it. For an example we might ask a junior dev:

  • Implement fizzbuzz

  • Now we need it to handle numbers 1 - 200

  • Now we need it to print "foo" on %7==0 and "bar" on %9==0

  • Now we also want to want to output not only to standard output but also to another interface

  • Now it reads the input number array from an HTTP get

Or whatever. The difficulty scales to experince level. I like this because thats what you'll do at your job - negotiate requirements, write code and maintain it. You'll get a feel at how good they are at writing maintainable code, as well as their views on testing/refactoring. We let them bring their own computers and do it in the own language/IDE if they want. We'd even let them google stuff if they asked.

11

u/nokoko Sep 22 '20

What would you do if you received 2k resumes per day, every day selected the best 100 to take your test and 90% of the candidates pass it with a perfect result? Who do you hire at the end of the month?

11

u/LUV_2_BEAT_MY_MEAT Sep 22 '20

The best cultural fit? The most relevant work experience? Other actually relevant things to the job?

6

u/nokoko Sep 22 '20

Does the job at your company involve anything harder that what is in the test, or is it a good representation of the complexity in the day to day work? If that's the case then you don't need to hire the best engineers, so the approach is understandable.

The challenge in hiring at big companies is that you want to present a hard problem (they want the best engineers) that can be completed quickly (people's time is valuable) and does not weed out people because they lack some exact domain knowledge. There are not many of such problems.

7

u/LUV_2_BEAT_MY_MEAT Sep 22 '20

But thats the whole problem: DS/A questions don't give you the best engineers, they give you the people who are best at solving DS/A questions. DS/A is a learned and practiced skill. Theres a whole industry now in getting better in those types of questions that exists for the sole purpose of doing well in these interviews. While these types of questions might provide partial insight into their abilities, things like technical discussions are equally telling: describing past projects, why the did the things they did, why they chose the technologies they chose, what didnt work, what they'd do differently, etc. The coding exercise I described is part of that holistic approach. I know you mentioned people's time is valuable, but again, if you don't take a little more time you dont want the best engineer - you want the best DS/A solver.

2

u/nokoko Sep 22 '20

Unfortunately these metrics are very subjective and hard to use to rank 1000 people and select the 100 best candidates in an unbiased way.

The challenges in the interview process between large and small companies differ a lot, so anyone copying FAANG practices in a 50-employee shop is making a mistake. Similarly, you can't really think that any approach that works well at a small company can be applied as-is to a top tech firm that attracts so many more candidates.

2

u/KrypticAndroid Sep 22 '20

I like this one. I’ve done something like this before and it felt relevant.

→ More replies (3)

2

u/badtux99 Sep 22 '20

Work sample tests, where the engineer is assigned actual work to complete, are what currently have proven to have the best correlation between interview and actual job performance. The research shows they have a 54% correlation with future job performance.

In other words, they work *barely* better than just tossing a coin.

1

u/foundboots Sep 22 '20 edited Sep 22 '20

I love coding interviews where the intent is to implement a contained system that solves (or helps solve) a real-world problem. Sure, it's become something of a meme at this point, but I think the LRU cache is a perfect example of this. Solving it well shows a command of data structures, programming, and reasoning.

Edit: thanks everyone for reminding me that this is a common question that many people have memorized the answer to. I say as much above. I’m just pointing out that this type of question is preferential to the brain teasers most companies use.

5

u/GhostBond Sep 22 '20

Solving it well shows a command of data structures, programming, and reasoning.

Like all these, it simply shows that you've worked and memorized interview questions.

4

u/[deleted] Sep 22 '20

Sure, it's become something of a meme at this point, but I think the LRU cache is a perfect example of this.

LRU cache is such a common question now. I've had it three times and I have it memorized down to muscle memory. It used to be consider a "hard" question just a few years ago. It's super easy to implement when you find out about the doubly linked-list solution

1

u/MishMiassh Sep 23 '20

Ask them to debug a template error in C++.

The answers are all there, in the error message, but most coders will stare blankly at it for 10 minutes and try to shotgun solutions until it compiles.
And if doesn't, rewrite everything templateless.

→ More replies (3)