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

0

u/[deleted] Sep 22 '20

[deleted]

27

u/Diabolic67th Sep 22 '20

The last line in every pseudo-code algorithm should be "check google to find the better way of doing it."

6

u/Belgand Sep 22 '20

Can I find an solution to this? Yeah... probably if you give me a decent amount of time. Even though I honestly suck at math. But if you want it done well, I'll track down a rigorously tested algorithm developed by mathematicians who've spent several years on the subject and then show how to implement it.

0

u/[deleted] Sep 22 '20

[deleted]

6

u/fried_green_baloney Sep 22 '20

Most of the people like that aren't interviewing for jobs where you have to solve those kind of problems.

→ More replies (4)

17

u/[deleted] Sep 22 '20 edited Sep 22 '20

I think the idea is what if you run into a problem you can’t google? Or what if it seems like a very specific problem you can’t google, but it’s actually the composition of 2 smaller problems that you can google. I know I’ve run into a few problems at my job where if I didn’t know some basic candidate approaches, I’d be googling into the ether.

But if you’re talking about, you know, this candidate doesn’t know that dijkstra’s algorithm doesn’t work with negative weights so that’s a reject, then that’s ridiculous.

But like if they don’t understand recursion or why you’d want to use a map over a list, then that’s pretty telling.

4

u/Fairwhetherfriend Sep 22 '20

I think the idea is what if you run into a problem you can’t google?

Can you give an example of a problem like this? Because, to be perfectly honest, I've never, in my entire career, run into a problem that I couldn't google.

3

u/[deleted] Sep 22 '20

Sure. Recently at work I had to access indices of an array randomly, and only once. If I look up solutions on stack overflow, I find lots of ways to just pick a random index given the length of the array, but that’s not an acceptable solution. How would you go about googling something like that?

6

u/Fairwhetherfriend Sep 22 '20

I still don't really buy that this is an "un-googleable" question just because the solutions you found didn't give you exactly what you wanted. Google is still a powerful tool for cobbling together a solution that works for you out of other solutions that are close, but maybe not exactly what you want.

2

u/[deleted] Sep 22 '20

Sure, how would you use that solution cobbled with something else? Because in my mind, it heads down the complete wrong path and is a good example of why you can’t just google everything. The approach I went with just leveraged my existing data structures knowledge - it’s not something you’d find on stackoverflow.

→ More replies (5)

2

u/DRNbw Sep 22 '20

Shuffle the indices randomly?

1

u/[deleted] Sep 22 '20

You could do that. I considered that but it was awkward for my use case since you’d have to hold a reference to both the array and the current index, it wasn’t something I could just iterate over once and wash my hands of. Anyways, if you looked on stackoverflow, you’d mainly find questions and answers based on accessing a random index.

10

u/badtux99 Sep 22 '20

Most real-world problems have existing real-world solutions. I have an entire bookshelf of algorithms books here. I don't need to be implementing a sort algorithm in a job interview, I have a dozen sort algorithms five feet away from me and just need to choose the best one for the specific application.

Which is the big issue with these artificial problems. Without the entire context it's impossible to choose the "right" solution. Reminds me of one job interview I had where I was asked to solve an artificial problem of finding a specific piece of information. I scratched my head and said "there's a dozen different ways to solve this problem, what's the general problem you're trying to solve?" "Finding stuff in a cache based upon MAC address." "Ah yes, then you want to do a hash table, next question is whether there's a maximum number of hash values that you want to store in which case we can use a fixed hash table, or we can used chained buckets if you want computer memory to be the limit. We also need to think about expanding the number of hash buckets based upon the number of MAC addresses we're storing if additional clients come in. What are the criteria of your network appliance? How many clients per appliance are you planning to handle? We need to size things appropriately to start, because rehashing is very expensive. And then ...."

Yeah, I got that job offer. Ended up turning it down for something else that was equally interesting.

0

u/[deleted] Sep 22 '20

[deleted]

5

u/[deleted] Sep 22 '20

But if you don’t have enough existing knowledge to know it breaks down into 2 problems, you’re out of luck.

0

u/[deleted] Sep 22 '20

[deleted]

2

u/[deleted] Sep 22 '20

Depends on the problem. If you had a problem disguised as some combination of things you didn’t know, like a topological sort or BFS or heap problem, then you’d probably come up with a bad solution.

Like a couple months ago I had a problem that required BFS and cycle detection, but the actual problem itself was following urls embedded in a webpage’s HTML recursively and seeing where they terminated and how many hops each path took. I don’t know what I would have even googled for something like that.

→ More replies (3)

1

u/strdrrngr Sep 23 '20

But like if they don’t understand recursion or why you’d want to use a map over a list, then that’s pretty telling.

It's interesting that you mention this. When I was still a junior dev a number of years ago I was contacted by a recruiter and decided to take the interview they were pitching. At the time I had done only a few technical interviews and knew that I might struggle if they asked me an algo question. The technical portion begins and the guy asks me to write a function that calculates the Fibonacci number at a specific position. I am pretty excited at this point as I've practiced this exact problem a ton of times. I write a function using a for loop and Bob's your uncle I've just aced the technical interview! Then he asks me, "can you write a recursive function to do the same thing?" My heart practically stops because I had never actually written a recursive function. I tell the interviewer that I've never done that, and at that point basically know that I'm not getting the job. He says, "Oh, well no worries, let's go through it together." Needless to say, I didn't get the job and I understood why but, I always felt it was really generous of that interviewer to take 20 minutes to teach me something.

5

u/gopher_space Sep 22 '20

and if it's something new to me, I'm going to research it to determine the best solution. That doesn't make me a poor engineer

My entire career is essentially scamming people into paying me to learn. If I find something new then nothing else is happening until I have a general idea of how it works and fits into the system.

Would you fly on an airplane designed by someone who didn't feel that way?

3

u/munificent Sep 23 '20

The interview questions companies like Google are designed to not require research, just thinking. In the example from the article, the interviewer shows you the layout of the number pad and explains how knights move if you don't already know.

All that remains is to see if you can get a simple description of problem and break down into something mechanical that you can make a computer do. That's the skill they're hiring for.

Sure, you can probably Google for the answer that someone else has thought of. That's obviously an important part of the job—Google doesn't want people who re-invent the wheel all the time. But that skill is common and easy to learn. The harder, rarer skill is the ability to work through novel problems and come up with original solutions. Google wants people who have both of those skills, so it makes sense that focus on testing for the rarer skill in their interviews.