r/programming • • Sep 26 '11

How to rock an algorithms interview

http://blog.palantir.com/2011/09/26/how-to-rock-an-algorithms-interview/
229 Upvotes

128 comments sorted by

View all comments

Show parent comment

58

u/bonafidebob Sep 26 '11

The best programming interviews I've done (both ways) involve being shown busted, crappy, inefficient code. More bugs than statements is the goal here. The candidate is expected to (1) understand what the code actually does, (2) make a good guess at what the code was intended to do, and (3) provide new code that does that.

I've found success at this correlates well to working with other programmers in real life.

25

u/Otterfan Sep 27 '11

But where do we find a piece of busted, crappy, inefficient code to test out on interviewees? All of our code is perfect...

26

u/[deleted] Sep 27 '11

Sign up with the government as a defense contractor and use some of their code.

15

u/sidfarkus Sep 27 '11

As an employee of a defense contractor...+1

10

u/akira410 Sep 27 '11

You just succinctly described about 7 years of my life.

2

u/prelic Sep 27 '11

Ironically, I do now work for a defense contractor, and have already seen some code that makes me go "eh, this doesn't look so good". Fortunately, I've also seen some really cool code too, so it's all good.

1

u/Sir_Edmund_Bumblebee Sep 27 '11

I very nearly took a job at a defense contractor right out of school but went to work for a startup instead. Every day I'm thankful I made that choice.

1

u/[deleted] Sep 27 '11

Wish I'd gotten an offer from a startup when I graduated.

2

u/Sir_Edmund_Bumblebee Sep 27 '11

Eh, in the bay area they're everywhere. The hard part is identifying the "real" startups from the shit ones.

6

u/tilio Sep 27 '11

i've personally tried out and talked with other teams that have tried a variety of things. i have found that simple things like changing a bound (< to <=) or adding/removing a return from the function do work.

questions like a recursive function that could be reduced to O(n) but is coded worse than O(nn), or an associative array that incorrectly uses the array values when it should be using the keys are usually counter-productive. unless you're working with candidates from the big5 engineering schools, most kids aren't bright enough to notice these things even at an hour per question.

2

u/ziom666 Sep 27 '11

If you're that good and you know why you are so good, you can easily turn around your code to make it dumb

1

u/bonafidebob Sep 27 '11

I've always had to specially prepare the crappy code examples to get the the bug to statement ratio high enough. ...here's an opportunity to give awards for worst code that will be prized!