Live data from Hacker News

How to Rock an Algorithms Interview

blog.palantir.com

141–150 of 169 posts

Re: How to Rock an Algorithms Interview

#141
This is a well-written article. You've acknowledged an interview process, and you've provided very good advice for candidates who may encounter a similar one.

Ideally, both hirer and hiree would obtain perfect insight during the interview, and an alignment of skills, personalities and potential could be determined and made obvious to both parties.

We cannot obtain such insight, and yet hiring decisions are still made every day. Some work out, some don't.

As in most things, companies must optimize toward some strategy that produces results consistent with their priorities. If each of your programmers must be able to define - not just implement, but actually recall - breadth first, depth first, big-o notation, and others, I suppose your strategy will have to include such questions. What better way to determine whether your candidate can memorize definitions than to ask them for them?

But some parts of the common technical interview exist simply because the interviewers themselves aren't aware of any better strategy to obtain the insight that really matters. Is your culture easy-going? Do you need a certain kind of creative influence on your team? Is it really true that your programmers need to program algorithms at all?

My point is really quite simple: to alleviate the feeling that we're passing over good people, we should alter the interview process to give the candidate ample opportunities to show us they're a good fit (and that we're a good fit for them. For the record, I never accept offers from companies that ask me lexical structure or algorithm questions, especially if those questions are posed by peer-level interviewers - it suggests a non-performing competitive rather than cooperative atmosphere). We should identify, if we can, the priorities of our team, and then attempt to find a strategy that is optimized for presenting the candidates we're seeking in a favorable light.

(I'm leaving this comment because you've written a post that is less about improving the recall or application of algorithms, and more about helping a candidate show you they're capable.)

Re: How to Rock an Algorithms Interview

#142
post #21

FTA: You should know these data structures inside and out. What are the insertion/deletion/lookup characteristics? (O(log n) for a balanced binary tree, for example.) How does one achieve this? Not just being familiar with data structures and algorithms (I am), but being fluent in them, to the extent that you can produce the Big O complexity for different operations off the top of your head. I didn't have a tradition…

This is ringing true. It somehow illustrates how essential computational complexity is because you're totally fucked up if you have no clue--yet how rarely you actually bump into the question of complexity in real life.

I'm self-taught and I've read and learned about computational complexity several times from various CS books and later Internet since I was maybe fifteen years old. I know how O(1), O(lg n), O(n lg n), O(n), O(n^x), and O(x^n) scale and which kind of algorithms roughly belong to which order of complexity.

However, keyword being several times.

I so rarely bump into these that I don't actively remember if heapsort is lg n or n lg n, or how the best-case, average-case, and worst-case complexities differ exactly between heapsort, quicksort, and mergesort. (I do remember that mergesort had a good worst-case behaviour in comparison to the others, at least quicksort, but I'd really have to check the bounds separately.) To mitigate this, I've guiltily re-learned them several times--I like reading Knuth or other CS books per se, just for fun--but like anything you don't need you do have a hard time remembering.

However, I do recognize them all being lg-something and looking up the various bounds is just a Google search away. Further, I do recognize the complexity orders in the sense that I might prototype something and initially stash items into a linked list but make a mental note that accessing the list can potentially become a bottleneck because it's O(n) so I shall reserve some mind power to change it into some O(lg) tree or ordered array at some point.

But at the other end the truth is that you just have to have some idea about complexity. You generally don't need more than that, and when you do you can just re-study that portion of the subject in detail from a huge number of web pages.

For example, it's useful to recognize the obvious bottlenecks of O(n^x) and O(x^n) but if you do, you don't bump into them anymore. You might bump into O(n) bottlenecks because you left them there yourself, probably on purpose, but since you recognize what linear complexity can do you will generally just change the relevant data structures into O(lg something) and be done with it. And if O(lg something) code becomes a bottleneck, you usually have stupid access patterns elsewhere in the code; I don't remember ever seeing a binary tree alone having become the real bottleneck in any program with the rest of the code being optimal.

What's interesting is that I more often bump into problems with the physical representation of the data structure than the computational complexity. A big naive hash table can cause lots of cache misses unless you deliberately work to align your items withing as few cachelines as possible. The difference between accessing five cachelines rather than five hundred cachelines can be blasting. I know this kind of optimization wouldn't scale towards n⇒∞ generally but it can have a big effect on real-world programs.

Re: How to Rock an Algorithms Interview

#143
post #91
post #21

FTA: You should know these data structures inside and out. What are the insertion/deletion/lookup characteristics? (O(log n) for a balanced binary tree, for example.) How does one achieve this? Not just being familiar with data structures and algorithms (I am), but being fluent in them, to the extent that you can produce the Big O complexity for different operations off the top of your head. I didn't have a tradition…

> I work predominantly with server-side, interpreted languages, and I just don't run into the bottlenecks and performance problems that Big O-knowledge seems to mitigate. Algorithmic complexity isn't about performance, it's about scalability. A hand-written implementation in assembly that's O(N^2) will be slower than an implementation in Basic that's O(N) (or even O(N log N)) for a sufficiently large N. I suggest pic…

That said, if building basics web apps is all you want to do (e.g., internal enterprise applications) then you don't need this knowledge.

Watch it before deploying those big joins that worked so nicely on your development data set, then.

Re: How to Rock an Algorithms Interview

#144
post #21

FTA: You should know these data structures inside and out. What are the insertion/deletion/lookup characteristics? (O(log n) for a balanced binary tree, for example.) How does one achieve this? Not just being familiar with data structures and algorithms (I am), but being fluent in them, to the extent that you can produce the Big O complexity for different operations off the top of your head. I didn't have a tradition…

I'll give you my point of view. I'm young(21), I'm in my third year as an informatics student, and I feel greatly intimidated by all these hard stuff. I can barely write a working web app, even with all the hand-holding modern frameworks give me. I don't consider myself smart(i'm bright enough to be a programmer, but nothing more). Recently I sat down and thought about where I want to be in 5-10 years. I don't want t…

I would say that you will feel this way once you see someone doing half the difficult job you do, but because of his productivity and problem solving skills takes huge strides because of the lack of good folks in the 'outsourcing quality' work that you describe.

The day you see such a guy, you suddenly get a feeling about the what the hell are you doing being average among the crowd of algorithm writers, while you could actually be a leader earning great money and with a big designation.

As we age we carry on a lot of financial responsibilities and money will play a huge role in the choices you make. You may give a great interview and go on to work with the brightest engineers at google and get lost in the brilliant crowd. At that time when you start reviewing your choices, you will get a feeling that you could have been unmatchable only if you had chosen a more easier career path.

In short,

There is no point being an average guy among a crowd of brilliant people.

Re: How to Rock an Algorithms Interview

#145
post #125

Earlier quoted context omitted.

The thing is, it's very easy to end up using a bad algorithm without noticing. If you're doing a linear search over a collection of n elements, fine, but if you end up having to do it n -ish times, suddenly you're up to O( n ^2), and if n is ever a few million in reality, your app will enter a loop that's practically infinite. Meanwhile, sorting them would be O( n log2 n ) and intersecting two sorted lists is O( n ),…

This algorithm fetish is just stupid. If a function / program isn't slow then it doesn't matter and if it's slow the dev will notice. I mean, come on -- is the dev not going to notice a practically infinite loop?

It wouldn't be slow on "reasonable" testing datasets.

Do you time your app at various loads (including well beyond expectations), graph the performance and look for non-linear increases?

Re: How to Rock an Algorithms Interview

#146
post #131
post #117

Earlier quoted context omitted.

We once hired a guy with PhD in computer science & he was a (great) lecturer & researcher for many years. We got him to do some "complicated stuff". I'm not going to go further into the details in case he recognises this. After he left I went back to learn math for interest and got really into it. I now realise that literally six months of the work he did I could do in an afternoon as I now have a deeper understandin…

I don't have enough information to make any conclusions here. But let me add to the discussion that more often than not, it is an order of magnitude (or more!) easier to look at someone else's solution and understand it than it is to arrive at the solution in the first place. I am even willing to believe that, perhaps if the problem were very well-defined, you might be able to solve it in an afternoon. But if you wer…

It wasn't this. The example was trying to show that a lack of knowledge can be catastrophic in terms of productivity for even the gurus. He spent more than six months on this particular problem and if he had known more math (very typical of people in comp sci unfortunately) he would have been enormously more productive. The problem was formulated before he started any work on this, it really was his lack of (graduate level) math and statistics that caused this particular. I'm not blaming him, it's just he didn't have the tools in his toolbelt to understand the best way to solve the problem, and nor would anyone who didn't have a strong math background.

Math is unreasonably effective. Just like knowledge of basic algorithmic analysis. I don't think that should be controversial.

Re: How to Rock an Algorithms Interview

#147
post #144

Earlier quoted context omitted.

I'll give you my point of view. I'm young(21), I'm in my third year as an informatics student, and I feel greatly intimidated by all these hard stuff. I can barely write a working web app, even with all the hand-holding modern frameworks give me. I don't consider myself smart(i'm bright enough to be a programmer, but nothing more). Recently I sat down and thought about where I want to be in 5-10 years. I don't want t…

I would say that you will feel this way once you see someone doing half the difficult job you do, but because of his productivity and problem solving skills takes huge strides because of the lack of good folks in the 'outsourcing quality' work that you describe. The day you see such a guy, you suddenly get a feeling about the what the hell are you doing being average among the crowd of algorithm writers, while you co…

I have to disagree. How did those people become brilliant? Hanging around smarter people probably had something to do with it. That's why I joined HN in the first place, 1207 days ago I was probably among the most inexperienced, and stupid people on this site, probably still am, even though I've grown so much since. I think there is no shame in choosing the simpler route, but i can't make this choice for my self. I care too much about doing good work, even if i suck at it at the moment.

Re: How to Rock an Algorithms Interview

#148
post #4

>Given a whiteboard and one hour, determine whether the person across from you is someone you’d like to work with, in the trenches, for the next n years. If we ignore the requirements of one hour... Brute force: Hire a random candidate that hasn't been hired by you before. Fire them when you get fed up with them. Hire a different candidate. Repeat. Greedy Algorithm: Develop the model for an ideal candidate, assign th…

have each applicant interview each other. The applicant that gets the most 'hires' wins

Nash Equilibrium: Nobody gets hired.

Re: How to Rock an Algorithms Interview

#149
post #90

Earlier quoted context omitted.

I've been doing this exact same thing to learn. I read an interview question that asked how to sort a linked list. I tried implementing it on my own. Later I looked online to see other implementations and compared with my version. I was a little bummed to see my solution wasn't ideal but it only made me dig deeper. Later on I found some Stanford lectures, particularly Programming Abstractions by Julie Zelenski (aroun…

The Art of Computer Programming (TAOCP), Knuth http://www-cs-faculty.stanford.edu/~uno/taocp.html

That's pretty heavy going though — I remember my algorithms lecturer suggesting we should only get those tomes for the geek points. Meanwhile, Cormen, Leiserson, Rivest and Stein's Introduction to Algorithms is relatively cheap, has good explanations, a more modern presentation of psuedocode, and a breadth of material that covers all the algorithms you could be expected to know as a general programmer, plus some more.

Re: How to Rock an Algorithms Interview

#150
post #21

FTA: You should know these data structures inside and out. What are the insertion/deletion/lookup characteristics? (O(log n) for a balanced binary tree, for example.) How does one achieve this? Not just being familiar with data structures and algorithms (I am), but being fluent in them, to the extent that you can produce the Big O complexity for different operations off the top of your head. I didn't have a tradition…

For your next side project, read CLRS and force yourself to complete a reasonable number of the problems (say every other problem, or every nth problem).

Then I think it will stick.

If you really don't need this info, then don't waste your time. To work at a place like Palantir, you do need this info.

Post reply on HN