Google Interview Questions Deconstructed: The Knight’s Dialer
alexgolec.dev
alexgolec.dev
My guess is that many hiring practices will change(and are changing) over time based on the internal work that people are doing to drive better initiatives, and less based on comments on HN.
Personally, I would like to see what people thing about the actual solution to this particular problem...
The problem that so by now many companies have been infected with the idea of using "Google's rules" as a playbook that it's still going to take several years for the contagion to wash out of the system.
Meaning we need to keep pushing back on multiple fronts. Given the insidiousness of the problem (and the psychological cost it has imposed on a generation of engineers; not to mention the sheer time cost) -- public exposure, followed by heaping mounds of ridicule (you can call that "complaining" if you like) would seem to be not only a valid, but unfortunately necessary part of our suppression strategy.
Otherwise, the people who keep foisting these questions us (as if they were a cool and nifty way to size up candidates) -- just aren't going to get it through their heads.
Personally, I would like to see what people thing about the actual solution to this particular problem...
I used to enjoy solving problems like these, during my high school and college years. Sometimes really, really enjoy it.
But now that I build real systems for a living (which generally involves much meatier problems to solve) -- and it's become part of the standard hazing process in far too many shops, for far too long -- I couldn't begin to care less.
At the most extreme, these questions are a test for whether the candidate had the same CS professors as the interviewer.
The problem is so many other companies have copied this practice because hey, Google asks brainteasers and gets the best candidates, so we should do it too!
On a more general note, anytime a problem admits a dynamic programming solution, there almost always is a graph based approach.
This concept was introduced to me back in my algorithms class and is pretty useful. For anyone looking for a longer explanation, page 167 of the textbook [0] has the nugget and some examples:
>Every dynamic program has an underlying dag (directed acyclic graph) structure: think of each node as representing a subproblem, and each edge as a precedence constraint on the order in which the subproblems can be tackled.
[0] - PDF: http://algorithmics.lsi.upc.edu/docs/Dasgupta-Papadimitriou-...
Whoa, this is something new for me. For e.g. how would you transform calculating nth fibonacci number into a graph problem?
This is still pretty specific to counting paths in the same way the original knight problem is, though.
The other comment is talking about how you represent each state for the recursive function as a vertex, then connect it to its dependencies (basically taking the recursion tree, but merging identical calls).
Consider the following graph. The nth fibonnaci number is the number of possible walks from n to 1.
(I made a mistake in the picture, there should be an edge from 2 to 1).
Probably been used in CS longer than “caching”.
That doesn't give you a big-O speedup, but it should be a 2x performance improvement for the algorithm that is linear in the number of hops.
* Can the person program at all. * Do they consider the performance of possible solutions. * Are they good at explaining their thought process. * Do they consider edge cases? * Do they write tests?
I'm not saying that it should be the only interview, or it is the most important. But it clearly provides differentiation between candidates. I'm also not saying it is the perfect way to get this differentiation, but I think it is far from "terrible".
All good things to look for. The problem is, day-to-day you don't have to do all of those things in 45 minutes while several people at the table watch you. Personally I'm a fan of a short programming exercise (perhaps even this problem) that you can take home and walk through with the team at a later time. I know those are detested by some, but I think they're fair (assuming the task is not something outrageous; something that can be knocked out in an evening perhaps) and give a much better idea of what an employee is capable of.
That's what you'd like to think it's testing for.
In reality, it's testing for: "Here's a hoop - would you like to jump through it for me please? BTW not only will stumbling or even hesitating pretty much disqualify you - we love to dish after hours about those who fail to make the cut."
Furthermore, you’re now selecting for people that are highly willing to “spend hundreds of hours doing tedious bullshit.” If you were a CEO, is this the type of people you’d want to stack your organization with?
Or you could have tons of experience deploying robust production systems but have never happened to learn / need to use dynamic programming, in which case coming up with it in 45 minutes during an interview is not going to happen.
Sure, but not everyone went to college or studied computer science / math. This seems like one of those problems that's really just testing a very specific type of preexisting knowledge.
Anyway, Google no longer has this question. Once it gets known outside Google bans it from interviews. Sometimes people give banned questions but in general they don't and it is taken into account. I remember it being popular as a question 4 years ago, popular questions tend to leak quickly and get banned though.
Sarcasm aside, the very fact that they ban questions demonstrates how useless these types of questions really are.
If you ban it because people might know it due to its popularity then what are you testing for? I thought it was for whether a candidate could solve the problem, but it appears to be to check which percentile of a special 'knowledge' club they belong to...
I'm also not worried if they make a good solution, or even get a solution at all. But almost all candidates can start making progress, come up with some possible solutions and tell me about those solutions.
[1] https://en.wikipedia.org/wiki/Diagonalizable_matrix#Applicat...
Also given that this is a discrete problem moving to floating points like you'd likely have to do when you diagonalize could easily lead to errors in the final answer.
Writing an unrolled dynamic solution as opposed to a simple cache is an extremely error-prone mental gymnastics in my experience. The initialization procedure and indexing are especially susceptible. Moreover, the resulting code is usually barely readable.
I wish people would stop expecting it. In practice, the memoization approach is sufficient in 99% cases, and having a 3% chance to make an error in unroll code that causes user data to be misplaced is a much worse option.
If the companies which employ such interviews are aware of the distance of those puzzles to the day-to-day labor of a software engineer, then I suppose it's OK. But seeing that the interviewer himself was direct hire from University with no outside professional experience makes me wonder whether they are creating their own ivory tower. In case of Google this seems to work out for them (they decidedly wanted to make things different than then already established enterprises and having seen those, I say more power to them), but will it for others?
I didn't get the log(n) solution until I found it existed at the bottom, but once the author mentioned it's existence, that took less than 5 minutes to figure out. I didn't code that up, though.
I'm probably an above-average programmer, but I'm not a 99.99% outlier. I interviewed early Google. The questions were tough for me (much more so than this one).
Things which jumped out at me: "The better the candidate, the fewer hints I tend to have to give, but I have yet to see a candidate who required no input from me at all."
I read this as "We're scraping the bottom of the barrel for candidates. Our candidates are nothing like those who applied to Google circa 2000"
And: "I didn’t even know it existed until one of my colleagues came back to his desk with a shocked look on his face and announced he had just interviewed the best candidate he’d ever seen."
I read this as: "Our employees are dumb. In using this interview question for years, none of us ever noticed the obvious."
What's going on there? I mean I can see messing up an interview question like this under the stress of an interview (I literally confused linked lists and arrays in probably my worst interview ever). But no candidate? Ever? And no employee? Come on.
There's something deeply wrong at Google. It's been deeply wrong for a few years. I hope someone fixes it.
Google does not usually ask 2 questions. You may/should get harder follow-ups to the original question, which is a good sign.
But I kind of miss the old Google where you DID need to be a genius. I interviewed with Google probably around the year 2000, and there was a genuinely hard ball packing problem. I'm kind of curious what happened. Anyone who could answer that question would find this one trivial -- and not just the dynamic programming solution, but the O(log n) one which apparently no one at Google (or even applying to Google) noticed.
What I hate about Google is that everyone there still thinks they're a genius. In 2000, it felt okay, since for the most part, they actually were. Today, it's kind of obnoxious.
Fwiw this is very much untrue. While this person may not have known the optimal solution, it's well documented within google.
> What I hate about Google is that everyone there still thinks they're a genius. In 2000, it felt okay, since for the most part, they actually were. Today, it's kind of obnoxious.
News to me ;)
There are certainly places where I think Google is a world-leader. But that doesn't require or imply that everyone be a super genius.
On the whole, it actually worked very well. Everyone wanted to work there because you were surrounded by top people.
Early Google: Phenomenal ability to build effective, high-quality products. Everyone wants to work there. Stainless reputation with the public.
Current Google: Limited ability to build effective high-quality products (but retty good at sustaining the successful products they have). Mixed reputation as an employer. Mixed reputation with the public.
You can extrapolate from there. I'm concerned about the second derivative.
I think the second piece there is employee growth. In 2001, Google had 300. In 2004, it has 3,000. By 2011, it had 32,000. today, it's over 100,000. You can't quite fit an exponent to it, but it's pretty close. If revenues don't keep growing exponentially....
I'm not implying it's failing, by any means, but it's gone to the same place as any other large corporation, and not a strong position to maintain pole position from.
My first solution was matrix multiplication -- I remember distinctly in undergraduate discrete mathematics learning that matrix exponentiation solved the hops-on-graph problem. I did not think to convert to binary to make logarithmic time, however.
It's not the fastest algorithm (by big-O; probably is in practice), though. You can do a matrix decomposition, exponentiate the eigenvalues, and convert back. Speed will depend on how you do the exponentiation, and that's gets into a pile of optimized numerical methods.
Edit: This applies for senior engineers as well.
From observation, many super sharp CS people very frequently want to write systems from scratch, get bored, then move on. It's really hard to pull them back to use off-the-shelf tech, don't over optimize, etc. Many of the best folks I've worked with in these roles are not CS majors at all (EE, ECE, etc) and this algo screening would filter them out.
There is an argument to be made here about career and skill growth. I left my previous job which was basically business-logic-to-CRUD-in-a-complex-domain simply because I stopped growing there. The moment you stop growing in software industry is the moment your career dies, at least that's my perception at this time given my personal experiences.
Solution: Make a test to test if people can do B. Studies correlate ability to do B with ability to do A.
Complication: Lose lots of candidates who can do A but choose not to get good at B.
Solution: Pay tons of recruiters to pound the pavement and turn over every rock and make sure every tech worker in the world applies.
I think they know that and they're okay with it because they have the volume and cash. I think they routinely tell you to try again.
Brainteasers are like "how many ping pong balls fit in a 747" or "you wake up an inch tall in a blender, the blades start spinning in a minute. How do you survive."
The problem itself appears to be nonsensical with no real world value but as long as it is a well defined problem with a concrete solution then it should be fine. Ideally the interviewer should be looking for how you approach the problem and what you do to obtain an answer (whether they do or not is a separate topic)
Granted, the 747 question also technically does have a concrete solution I guess, but I would end up asking things like what's the volume of a 747 and the dimensions of a ping pong ball and then point out there will be gaps as we fill the 747 with balls so it's not simply dividing the volumes, write a program based on these observations, give a disclaimer that it will most likely be inaccurate, and hope that is good enough to pass.
But that blender question... uh yeah... I'd probably spend too much time asking clarifying questions to actually come up with something plausible.
Whether or not someone is about to add ice seems like a pretty important variable.
This one does seem useful. Being able to do back-of-the-napkin (i.e. fermi problem) calculations is a pretty good skill.
The reason the 747 question is bad is because it has little to do with programming and a lot to do with how much you happen to know about planes and ping pong balls and how to estimate volumes of irregularly shaped objects, none of which have much if any correlation with programming ability.
Similar but smaller questions along these lines are given to more junior candidates often enough too, as one of multiple questions.
How do you know? Maybe the interview was for a position on the AplhaZero team.