How to Crack the Toughest Coding Interviews
gklst.tumblr.com
gklst.tumblr.com
The next two members of his group never met me, so all they know about me is the sound of my voice and facts on my resume, and during the phone interview they came across like they thought I was some dimwitted old duffer and that I was Googling the answer because I was doing stuff on my own command line. The guy in charge told me to stop coding, because as he said, "You will take too long and never get done," [1] even though I've been coding in dynamic environments for 15 years, and so my problem solving techniques are all oriented around very rapid iteration. So he effectively disarms me, then proceeds to be the annoying kind of smarmy pair programmer and tell me everything I'm doing wrong as I'm coding. (All of which I could catch if you just let me at it.)
Just a few minutes after the interview, I send him running code, then correct code that solves his problem. (So he's wrong! - [1]) He was probably some fresh-faced kid out of school who doesn't understand other than a C/Java workflow.
The lesson I've learned over the years, is that an organization that interviews you incompetently is one that you don't want to work for anyways.
EDIT: Another thing that really irks me about this interview, was that they sprung a relational data modeling problem on me. That has almost nothing to do with what I'd be hired for, and most importantly they left out the key premise: They're looking for a generalist who can just hop in and do whatever. (Which I can do, as well as being methodical and researching the problem first.) So basically, they're looking for some fresh-faced kid like them who's fearless because they don't have the experience to know that your first model is going to suck. If they had let me know this premise: "we just want to see how you handle just getting something done" versus "we're going to grade the quality of your ER modeling" then I would have done that part totally differently.
Exactly the kind of group I don't want to work for.
For example:
Interviewer: "How you implement this calculator program?"
Me: "Well I would try to read a number...."
Interviewer: "HA! You cannot assume the type of input"
Me "Okay, fair enough... does the input reflect a valid math expression?"
Interviewer: "Of course, why would you ask such a question."
In the moment I really felt like the (relatively young) interviewer way trying to lead me in the wrong direction, and then when I realized I needed to make no assumptions, criticized me for trying to clarify other parts of the problem.I didn't get that job, but after that experience I was hardly disappointed.
There's a lot of information in tones of voice.
One I used to ask was do you have IS9002/BS5750, but that was 15 years ago and there are better questions to ask. A good question is also sometimes better than a good answear as it shows you understand things from another perspective and have the ability to ask questions instead of blindly accepting what you are told all the time if your unsure.
So what are your favorite questions and not how much TAX did the company pay type questions, the ones that give you lots of wonderous information and yet still puts them on there toes a bit as well if they are weak in some area's of managment/running the company of methodology. I asked what Q&A methodologies do you use in a interview once for a company called RIM; Was not a great answear. My question about IS9002/BS5750 was one which showed how well organised the company was at the job in hand and how well documented the role was. The answear tells you what kind of mess your getting into and also if you should be asking for more money (danger money if its somebodies spagbowl code/system :).
So what questions as a programmer do you ask the company in an interview, that is applying for your service. Anybody have one they care to share?
Do you use git?
How do you do ticketing?
What's it like working here?
In my experience engineers at big companies will not give you an answer to those, but canned marketing responses. I don't know why.
Your right about the canned marketing responses, most of those forget the interview is a two-way process sadly and deem any question you ask as a waste of there time, that is a sign you should take note of.
>What's it like working here?
ask them
>What do you like the most about working here?
If they give you something like "the stability" or "the high pay" those are generally bad signs. Better signs would for example be "the great people I get to work with every day" or "the autonomy to get to choose what I work on".
But indirectly asking questions is the way and it is those clever ways that are the types of questions i'm realy interested in, like my question about ISO/BS standards, it opend them up to so much more than a simple yes and no and gives you insight into other area's. Like working conditions, are they documented well, badly, not at all, do they even know about those standards, is it something there looking at (often crops up that last answear on many area's sadly).
Is the pay individual perofmance based or team based and is it limited/capped in that if I do 200% better am I capped at some rate of inflation % rise anyhow. I also like to ask about problems, what was the worst day like this past year and why and how likely is that to happen again. That tells you alot about so many area's and also opens them up into telling you how it is as well as allowing you to highlight your relevant skills and chip in with did you try this or that at the right times, even if you agree and play noddy whilst they talk.
One I always ask is can I have a look around the office, the area were I would be working if I was to be offered a position. That is useful in guaging there interest as if they are not interested they will come up with a reason why they can't do that, if they are keen for that you can see what your dealing with and also get a good feel from the way others have there desks decorated. Be they anal, stuffed south park toys, simpsons posters, collection of 2600 mags. Those type of things, you can get a feel on many levels from that.
Asking them how long they have been there is another good one, longer the better, but if they sound bitter then you can take that as not a good sign as well. Though if there two hyper only been there few months then they are sadly not realy able to give you a a true picture, so again take advantage of there hyper still all new to me as well fun happy time mood and take a look around.
Always a good one. I also like a variant on this if they profess to practice agile development:
>How do you implement the agile process?
More times than not, it's a waterfallesque implementation.
Every big company uses Remedy. Some just dress it up a little.
Someone asked me that once, and I thought it was a great question, so I stole it.
interviewer: What is Cassandra useful for?
interviewee: It's useful as a highly-available database if you can denormalize your data. What are you guys using Cassandra for?
interviewer: Well, we're using it to...
interviewee: Interesting. How's that working for you guys?
This not only can get you some valuable information to make your decision, but also looks confident as you're exercising some control over the interview. You just have to be careful not to derail the interview with this technique, or you'll come off cocky and arrogant.
I always ask for an example of a technical or tools decision that was made. I'm usually looking to see whether decision-making is well distributed or things get bottlenecked by a manage or lead.
Probably most of all I pick at how the organization decides what to build. I'll ask about features or products that have been sunset or rehashed, how requirements are discovered and communicated. How prioritization works. One of the easiest ways to get red flags here when applying for a spot on a team is to ask everyone I interview with what the team is currently working on. A large variety of answers makes me nervous.
Oh, and also big points off for "Yes" to the following: - Do you have an exchange server? - Do you have a sales team? - Is the person who makes the purchase decision for your product your primary user?
>Do you have a sales team?
If customers need to call in and speak to engineers or other non-business people to negotiate sales, that sucks. Having inbound sales people is a vital part of any good mid-sized company.
The problem I have with sales is that they're often very good at what they do. Once you have sales, you have two products. Your sales folks, and the thing people think they're paying you for. It gets hard to know which one is failing, or worse.. succeeding.
Not everyone is secure with a "F you, sign up online or else" policy. Good salespeople with domain expertise can be exceedingly helpful at introducing direction to the company - not just automatons who sell things.
And did you miss a negative in your last question?
From Google:
http://www.google.com/about/jobs/lifeatgoogle/hiringprocess/
From MIT:
http://courses.csail.mit.edu/iap/interview/materials.php
Steve Yegge's well-known advice:
http://steve-yegge.blogspot.com/2008/03/get-that-job-at-goog...
Essentially it seems to build down to knowledge of data structures and the ability to use them in concert to develop solutions on a whiteboard. There's more to it than that, but being able to code without an IDE is critical.
He says:
Don't say "choo choo choo" when you're "thinking".
God damn it. Now I'm going to have to fight the urge to do that during interviews!
EDIT I suddenly got it. They're doing long exhales. I think my kids might do this when they're pretending to work. Then again, they are kids.
A few days ago I finally realized why they said I'm not good enough at big-O to play with them (despite saying my coding was excellent). For some reason I had a mental block that day and wanted to implement hash tables as prefix trees every single fucking time.
I have no idea why. Of course I know a hash table is O(1), but for some reason, that day, I kept trying to convince everyone it should be O(N) (N=length of key) because it's implemented as a prefix tree in the background.
Idiot.
(For some reason programmers really love tries / prefix trees when answering on stackoverflow and such. I'd like to understand why -- tries are neat, but you don't see them nearly as much in actual use.)
O(N) only makes sense when you agree on what N means. When using big-O notation, always make sure you agree on the base N values you want to work with. In this case, it sounds like you interpreted N as the number of bits to hash, in which case yes, any sensible hash algorithm has to look at all the bits so it'll use an O(N) algorithm. However, the post you replied to talked about hash tables, a structure used to implement (among other things) maps from keys to values. For such a structure, N refers to the number of items stored in the table; hash tables have the rather unique property of supporting O(1) insertion, removal, and lookups (modulo amortization arguments about the size of the table).
(Yes I'm handwaving around the details. So is everyone who talks about big-O notation in connection with real software.)
I actually like people to point these things out, even if the amortized cost is constant in lots of real world usage. When talking about time complexity I appreciate attention to detail, rather then just hand waving and saying its constant. My answer is always, 'well it depends'.
Be careful though, back up your answers in a way that shows you do know what you are doing. Otherwise you can come off as blowing smoke.
Truly understanding writing performance critical code is a black art, and you need to understand more then just the big O of some common algorithms. Showing that you know that performance and complexity are hard and you know there are hidden costs that can bite you and tradeoffs you have to take into account shows maturity.
But the answer most certainly isn't "Well I don't know _exactly_ how python does dictionaries, but I would implement them with a prefix tree and there is nothing better". Which is roughly the answer I gave, in different settings. To five interviewers.
I think you're getting your n's confused. O(n) in the context of a collection applies to the size of the collection, not the size of the keys. Nearly all hash functions for strings are O(n) in the size of the string. This doesn't mean the hash table is O(n) for lookups.
If you use rehashing or a linked list to handle collisions that has another impact on the performance depending on what is going on.
If you choose to auto grow the hash table upon a certain number of collisions, this is another thing you have to worry about.
The process of lookup might use a precalculated cache of the hash code calculation if it is expensive and sacrifice some memory for this storage.
My point of all these examples is that the simple runtime of the collection isn't the whole story and lots of crap can happen under the covers. We stand on the shoulders of giants, but we have to know what weaknesses and strengths we are exploiting. While just picking the right data (or wrong) structure makes a huge impact, you need a lifetime of experience to really know what matters, and what the trade off of one or another is in a given scenario. Hard to test for that intuition and I always like people that interview with me that start talking about these sorts of issues.
Point was, worst-case time complexity isn't constant. I'd be happy to see more people get that right in interviews.
An amortized bound is a bound on the total cost of a sequence of operations. Loosely speaking, it guarantees that you can't keep hitting the worst case indefinitely. An average bound is averaged over all possible inputs, but doesn't protect you against hitting the worst case over and over.
And only people like developers would put up with being tested like lab mice in this manner for a job.
Why shouldn't you validate if a programmer is, in fact, a good programmer (which is a mix of many things, including intelligence)?
so yeah, ask me to program. i mean, srsly program. let's hack together for an afternoon; hell, let's do a full day of paired programming to knock out a small bug in your code base. you'll learn a hell of a lot more about what i know, how i communicate, steps i take when i do when i don't know something, and what my processes are. this soft, inter-engineer-social stuff is overlooked over far too often; i wan't to work with people who will amplify my process and abilities, and in turn i'll amplify theirs. smarts don't count for enough.
Comparing candidates is irrelevant. You just want N hires that can contribute in your environment.
Agreed. That would be bullshit. And those are bad interviewers if they do any of that. Companies like Microsoft, Google, Amazon, and Facebook don't do that, as a general rule. I'm sure you could find bad interviewers at any company though.
Programmers are almost never asked to program. They are asked to solve 50-year old CS problems on a whiteboard.
It always comes down to exercises from CLR lightly dressed up.
Programmers, however, must take a test. It's not an interview, it's a test. Pass or fail (regardless of what people say), it's a test. It's a test of which you have little preparation for. You hope that what they are looking for is what you can provide. What they are asking for is what they will test for (this is fairly often not the case).
So this is like saying "ex-Python-dev mailing list member".
It is irrelevant whether it's an honor, but as to whether it gives you insight, you are generally right but you did miss an important point:
The vast majority of people who are "members" of a given hiring committee often don't show up every week. A lot, in fact, show up never, but are still members. (for example, they were part of it years ago and nobody removed them, they got asked, said yes, never actually did anything, etc)
So while you are correct that it does give you some insight if you actively participated, simply being a "member" of a hiring committee is a necessary but not sufficient condition to say that you have that insight.
Lies of omission and all that.
In this case, I'm stating that I was a hiring committee member and not saying that I attended regularly, when I in fact did. This is not a lie of omission. At worst, you could accuse me of not offering additional qualifications.
But, yes, I could have been more extensive in my credentials. Unfortunately, "How to Crack the Toughest Coding Interviews by ex-Google engineer, ex-Google hiring committee member who showed up every week, ex-Apple dev, ex-Microsoft dev, author of Cracking the Coding Interview, and author of The Google Resume" was a bit too long :).
I expect the "newer" offices (relatively, of course) may not have this issue.
The interview questions I ask are more around problem solving and thinking out of the box but I deal at the web application level not building compilers, databases, etc.
What is a path through a cube? This seems like some weird combination of graph theory and geometry.
In this cube land question you can answear, how are you defining the centre and just revering that process will already give you the code you require. What they are doing you don't know so you have to ask, may be they are trying to reinvent a wheel and with that the best answear may be how to draw a circle as there question is flawed. This is the problem with made up interview questions, if they are based upon real world experience then you get a good question that you can truely answear. You may have a better answear or approach which with them having lived it, makes enough sence to know you would of saved them 2 days debugging that problem and thats from a quick chat walking of the street. If it is a made up question then your approach and alternative answear can be missed and ignored and your genius is not appreicieated.
You could of course write a program that would solve it (trivially), but it might take exponential time :)
Of course, the phrasing doesn't say they have to be lattice paths, so perhaps we can say a countably infinite number of paths of we're only considering integral (or rational) points and have no direction invariant. Uncountably many if we're allowing the reals. Still uncountably many if we allow the reals and have a directional invariant. We reach the realm of a finite solution if it's a finite set of points and we have a directional invariant or another constraint (e.g., the path might be prohibited from visiting any given point more than once). Most of these are still completely intractable as far as I know :)
To count paths in 2-space from (0,0) to (5,6), you have the operations "X++" and "Y++" which go right and up, respectively. Each increasing path from (0,0) to (5,6) has to be some permutation of 5 times X++ and 6 times Y++. So the count is (5+6)!/(5!6!) where the exclamation mark denotes factorial. This extends to higher dimensions by adding an additional operation "Z++". Then the count to go from (0,0,0) to (5,6,7) is (5+6+7)!/(5!6!7!).
I think you can easily write the recursion:
p(x,y,z) = p(x-1,y,z) + p(x,y-1,z) + p(x,y,z-1)
Leave out the term with x-1, y-1, or z-1 for the edge cases for x, y, and/or z equal to zero.With that in hand, it is easy to compute all values bottom up, starting with those where x+y+z = 0, 1, 2, etc.
Definitely fewer than (x+y+z)^3 values to compute, all of them in O(1) (disregarding cases where the numbers become bignums)
Generalization to any number of dimensions seems easy, too.
A closed form solution, that might be harder.
Basically, yes, self-avoiding paths.
This was basically a brief aside in her honors undergrad algorithms course, so the topic was a bit beyond what I was prepared for at the time :)
Counting self-avoiding walks is hard in 2D, too (http://oeis.org/A007764)
But as best as I can tell, they're considering each 1x1x1 space to be a node like a Rubix cube, and they want a list of all possible paths from the center node to the surface. I imagine that half of the question is making sure that the interviewee presses for details, because there's plenty of problems I see with the question right off the bat. If n is even, there's no single center node, so where does the algorithm start? Can the algorithm traverse diagonally by edges, or only by adjacent faces? Not to mention that there's an infinite number of possible paths for some values of n, assuming paths can cross themselves, for the same reason that there's an infinite number of paths from my front door to my car if I feel like walking in circles for a while.
I studied CLRS's Introduction to Algorithms and a couple of other books for about 2 months. Even then I could not answer the hardest questions during the onsite interview. And if you cannot come up with an optimal algorithm for a given problem, all of the items mentioned in the article (communication, clear coding, testing) don't really matter.
That's just not true and if any company is only interested in whether or not I can generate a correct answer under pressure in 20 minutes, then I'm not interested in working for you.
I'd suggest you read the section in the article about how you're evaluated. Yes, how optimal your solution is matters -- of course it does. This doesn't mean that you have to get an optimal answer though. You have to do better than the majority of candidates (maybe ~80% of candidates).
For some problems, being in the top 20% of candidate will mean getting the optimal solution. In other cases, it may not. The optimal algorithm might be trivial, and it might be more about coding skills. In another problem, it might be totally unrealistic to expect that a candidate needs to get the optimal algorithm.
Additionally, you seem to assume that since (according to you) getting the optimal answer is necessary, that it must also be a sufficient condition. That's obviously false. It's entirely possible that a candidate needs to get the optimal answer AND implement it well, in which case these other factors come into play.
I don't understand the point of this quibbling.
Say I was asked 30 questions; I missed 3 of them and didn't get hired. It's a reasonable to assume that these 3 questions were considered important in the general assessment.
> You have to do better than the majority of candidates (maybe ~80% of candidates).
I know, I said I read your book. ;-)
But that doesn't substantially change the story, it means it's likely other candidates got the optimal solution or got closer to it.
Of course this is all based on my self-assessment, since Google doesn't provide any sort of feedback post-interview. But I'm pretty confident that I went well in the other questions. 4 out of 5 interviewers were pretty nice in giving feedback during the interview, even if indirectly. E.g. they'd ask progressively more involved questions on the same topic, so I more or less knew when I had answered the previous questions correctly.
> Additionally, you seem to assume that since (according to you) getting the optimal answer is necessary, that it must also be a sufficient condition. That's obviously false.
No, I haven't made any such assumption. I only assume that getting the optimal answer was the "high bit" in my case.
Apparently this works for Google, and unlike other people who have failed to get the grapes, I don't call them sour.
Imagine: I walk in, get 27/30 and then proceed to be a sexist bigot who says I refuse to work on a team with gays or women and I decide to start claiming that you have to get 100% to get hired.
I'm not saying you did something like that, but you're just automatically assuming that that question was the pinnacle of your rejection and not the other things listed.
I mean, unless you've been implicitly implying that you're a perfect interviewer minus the 3/30 you missed...
That would be true if those answers were assess on a strictly correct / incorrect basis AND those were the only things you were assessed on. Neither of those are true though in this case.
It's very possible that the questions where you didn't get an optimal answer you actually did very well on. And that there are other questions where you got the optimal answer, but it took you too long or you made too many mistakes in coding. Or you just came off as arrogant. Who knows?
I've seen many many candidates make similar assumptions to yours -- thinking they bombed specific interviews, when in fact they did very well on those. You might be correct about why you got rejected. But it's even more likely that you're wrong.
But this is absolutely true: getting the optimal solution in all interviews is not a necessary and sufficient condition.
I gave my question to an algorithms professor and he didn't get the optimal answer.
Needless to say, I don't expect candidates to get the optimal answer.
I'm a current student still going through the interview process with Seattle / SV / Austin companies (big and small).
Every interview is the same:
- review resume
- 0-2 behavioral questions
- 1-3 technical questions covering design, data structures, algorithms, sometimes language specific (usually pointers)
Here are two recent questions asked of me this past week:
1. How would you detect the largest sub array (i.e. max sum of adjacent numbers) given an example array:
[ -1, 5, 2, -4, 6, 3, 9]
2. Given N cubes painted 1-6 sides (duplicate colors on a single cube is possible), what's the largest stack you can build such that all faces on each side are the same color? The stack is 1 cube wide and deep, solve for height.
Maybe wherever you're employed / looking for a job doesn't ask these type of questions. Congrats. However it doesn't change the fact that these questions are the norm for top tier US tech companies, and a quick glance at GlassDoor.com will corroborate.
Their effectiveness (or lack thereof) is up to the hiring companies to decide. Seriously, hot companies get flooded with applications (I believe Google gets >100k annually). They don't have time to sit down with you and pair program for an entire day, especially as a 1st or 2nd round screening.
That's a fun one. The obvious solution is O(n^2), but there's a less obvious way to do it in O(n). (I'm not giving spoilers, because this actually is fun to solve.)
I'm not worried about losing a potential job because I couldn't crack some obscure mind puzzle.
Alot of people who fall into the boat of being good coders with social skills of dead fish often have a hard time. One appraoch is to create some wonderous application and get broaght out, recruitment that way. Or in the process, end up refining there social skills to the stage that not only can they interview ok but are running there own company.
Coding interviews should be done via a shared terminal/IDE screen and chat windows, that approach would be more realistic to some. But I'm one of those people who don't socialise too well at times, interviews/exams, that type of thing.
I've definitely encountered people who were clearly good, and equally clearly sucked at interviewing, as an interviewer I had to ask myself the question "why?"
I encountered the following cases (among others)...
The ill-prepared - This may come down to background, some candidates didn't seem to know that they should prepare for an interview - this can be excusable, but in a world where advice about this is one web-search away is increasingly tough. Usually (but not always) this is a barrier to recommending hire.
The chronically nervous - This is always at least 50% my fault. I believe in asymmetric responsibility, as the person with more "power" in the situation, I feel part of my job is to help a candidate past their nerves; if this means my interview is entirely spent putting them at their ease to (potentially) do better with the next person in line, so be it. This has rarely been a barrier to recommending a hire.
The arrogant - "I can't believe you asked me such a demeaning coding question when I'm applying for a senior role, clearly my resume tells you all you need to know about my coding chops" - sorry, if I can't pierce this, no hire.
The inarticulate - often in this case the code speaks, even if the candidate can't, I usually associate this with nerves, sometimes it is language issues, sometimes stress sensitive speech impediments. I'm pretty sympathetic to this if the code speaks, but communication is part of the role so this is always a judgement call.
Can't code on a whiteboard - I'm inclined to call this ill-prepared, you should expect to have to do this coming into the interview, but I do get that this is equivalent and opposite from "inarticulate" - I will take a coherent and detailed description of a solution as being nearly as good as the whiteboard code, but there is a bottom line, you have to be able to show me your ability - sometimes one really insightful question or observation is all that it takes...
This avoids avoid that artificial write code as fast as you can with a whiteboard marker situation. Granted, it's not their regular dev setup and it's probably an unfamiliar keyboard and trackpad, but it seems to be better than the alternative.
For every interview I have done as an interviewee I have studied what I am likely to be asked, what their interview technique is, boned up on the language(s) in question, and tried to think of some interesting questions to ask the interviewer (the last one also includes learning as much as I can about the company and its history). I think these are the basics any interviewee should do - that's just the bare minimum for the big guys. For Google I was pulling out dusty old CS books and revising CS theory and that was still just barely enough preparation.
Meanwhile I've given interviews for a C++ position where the candidate hasn't even had a quick brush up on C++ recently. I've had candidates who do C++ as their JOB and not know how to initialize memory, someone describe "polyformic" behavior, and had a good 75% not know at all how virtual functions work. It blows me away.
Or maybe it's confidence? I don't know. I've been programming professionally for over 10 years. I think I should be able to sit down and work out almost any problem in an interview.
I've definitely been to interviews where I ran into issues and didn't get offers, but I've also been to interviews where I ran into problems and did get offers.
I guess, in my gut, I feel like studying for an interview is cheating a bit. It might not be the right outlook, but it's something I can't shake.
There is also a difference between an experienced industry hire - as you say, if you've been doing this for 10 years you can go into an interview and show them a pretty good picture of what they are getting - and a less experienced or campus hire, where what is important might be an expression of potential - the practice helps with letting the interviewer see that, if your interview is the first time you've tried to code at a whiteboard, or solve a problem with someone trying to push you to the edge of your comfort zone, then you are doing yourself a disservice.
I have, however, encountered candidates who just didn't know, they didn't go to a top school (or indeed any school), they haven't worked in this environment, they don't have any understanding of what to expect - even the simple web-search that would have warned them requires some level of a priori knowledge - not every candidate has that - I suspect most of these candidates do badly, but just watching how someone learns through a day of interviews tells you something, that higher level bit about learning when in over your head is one of the most valuable.
Thanks
Internal interviews can be a real eye-opener.
Also, it simply does not reflect in anyway what it will be like to work there or what it will be like to work with that person. One key reason is that the interviewer asks questions they already have the answer to and that unbalances things and results in an inaccurate analysis.
In real life, none of the people in the room would have the answers and they'd all be working together to solve the problem.
These people come and interview all day. The team would be better off just having that person tag along with them and work on real problems together all day.
I've noticed the strange ones seem to be coming from people that aren't prepared to be interviewing. So just a word of advice (and I'll elaborate with a blog post soon) to interviewers, please prepare ahead of time. I'm interviewing you too.
Asking the most abstract or complicated question possible probably won't help you find the people you're looking for.
I like using it to study for interviews. It's not sufficient by itself, but will get you 75% of the way there.
*Disclaimer: I'm 3 degrees of separation away from the author. :p
Mine would probably more practice with recursion, dynamic programming, graph theory.