Thursday, July 28th, 2011

The LibraryThing programming quiz!

Want to apply for one of the technical jobs at LibraryThing? Take the test below. If you can do it in under five minutes, let’s talk!

Background. I’ve been spending a lot of my time going through (read: “drowning in”) applications for our 2-3 open technical jobs. And I’ve been conducting a few interviews. The latter has demonstrated to me again the value of asking applicants to write code, especially simple code, during the interviews.

That interviews should involve simple code is now common wisdom in programming circles. The story is that a high percentage of programmers, even people with impressive resumes, “just can’t code.” Asked to do the simplest things—problems a good coders could solve as fast they could write—some spend ten or twenty minutes before they get an answer, or fail entirely. (See discussion by Jeff Attwood and Joel Spolsky.) I don’t go as far as others here. I think a lot of “slow coders” are probably excellent employees, making up for it in other areas. Some projects don’t need speed. Some people just need to spend more time programming; everyone was a slow programmer some time. But I know from experience that slow coders don’t work at LibraryThing. They don’t fit the LibraryThing development culture.

“Simple code” is critical. When I first started interviewing I’d ask people to solve hard problems. This didn’t work. As Spolsky’s famous “The Guerrilla Guide to Interviewing” argues, however, simple problems are just as good, or better. Simple problems test simple skills, and simple skills are the basis of complex ones. A programmer who struggles to loop through a bunch of words will be at sea performing far more complex tasks. If you can’t boil water your Toad in the Hole is likely to come out wrong.

Coding tests irritate a minority of people. One applicant said his resume should speak for itself. I have no time for that attitude—though I’m happy for the weeding help. Good programmers should welcome the opportunity to demonstrate they’re good at what they do. Heck, most programmers I know enjoy brain teasers anyway. They test themselves when no one’s looking.

The rules.

  • Time yourself.
  • Write this code in any language you want. Use your best language. If you can do many, PHP, Python and Javascript are preferred.
  • Write it out longhand or in a simple text editor.
  • I don’t care much about syntax. You can fix whether it’s isArray or is_Array later. If it has some obvious bug you’d fix in a second, fine.
  • This is not a trick question.
  • I’m not asking for some imaginary “best answer” that does everything in one line of self-writing code, or whatever.

The problem.

Input is a string—a paragraph of text. One of the paragraphs above would be fine.

Output is a report listing how many words there are with X letters, like:

10 words with 1 letter
20 words with 2 letters
7 words with 3 letters
15 words with 4 letters, etc.

How’d you do? Programmers employed by LibraryThing can do this in between 45 seconds and four minutes. We expect you to be in that range. If you’re applying for the sysadmin position you can be slower. (We think good sysadmins need to be able to program, but you don’t need to be a crackerjack programmer.)

If you’re in that ballpark in any language, go ahead and and apply!

UPDATE: We are NOT approving comments with the solution. We don’t want people to be exposed to it when they read this—it would defeat the purpose. We’ll approve them after the job is filled.

Labels: Uncategorized

21 Comments:

  1. Tim says:

    People are putting their answers in the comments, but I don’t want to show them now—it’s too temping to look down at someone else’s answer. I’ll approve their comments later, once we fill the job.

  2. fitz says:

    As an interviewee, I’ve always thought testing is good thing during an interview. It’s the one part of the process that i know exactly how well (or poor) I did. It also let me know if the boss is a sadist…

    However, two things I like to keep in mind:
    a) being put on the spot does affect the coding. coders are not stand-up comedians…we rarely do our job in front of strangers. when someone is writing code on the whiteboard, it doesn’t actually have to be 100% syntactically correct..it’s more how the problem is being approached, i guess.
    b) i don’t know why, but I can never remember phone numbers and regex statements. I have a ton of pages bookmarked that have a bunch of answers..even stuff that I know I know. It’s a security blanket thing I guess. It just makes things go faster and limits the number of stupid errors.

    Dunno…luckily I rarely have to make hiring decisions…

  3. Greg Ricker says:

    That was a fun quiz. I had the general idea in less then a minute. It took about 3 mins to code it in Java, Eclipse takes at least a minute to start up….!

    Good luck with filling the job!!

    Greg

  4. aqeeliz says:

    2 mins 30 seconds to write the program in PHP, much slower than I expected.

  5. Roger says:

    It took me about 15 sec to see the answer in perl, but I don’t touchtype (which some consider a major failing in a programmer), so It might take me longer to type it out.

  6. Tim Chase says:

    Is it picky to ask how you define a “word”? Letters only (or allow words like “Se7en” as a movie-title)? How about accented letters and other character-sets or Asian glyphs? The Perl/regexp “word” (i.e. “w+” which includes digits and underscores)? Contractions like “can’t” vs. single-quotes used in quotations? Hyphenated words? For pure 26-upper/lower characters, my Python solution took about a minute.

  7. Justin says:

    It took me 2 days to just read this post.

  8. Trevor Gryffyn says:

    Hmm.. pasted some code, the ‘awaiting moderation’ not makes it look like it stripped out half the code. Guess you’re not really asking for people to post solutions, but you’re allowing it for fun.

    I took about 10 minutes, but I can’t “release” code without testing it so I double checked the regex and such I was using.

    Simple challenge but fun!

    -Trevor

  9. Dana Bell says:

    The required logic is routine, something any programmer (teens included) should be able to figure out in less than a minute. But it did take me 8 minutes to type in the 12 lines of C on this unmarked keyboard.
    Don’t you want to focus on quality, clarity and speed? Sloppy php on the internet can be dangerous.

  10. David says:

    Took me about six minutes to write. Definitely rusty. Writing it in C lead me to do ASCII only, and after testing, I found I didn’t pluralize word correctly. (Also didn’t handle i18n correctly.)

  11. Brantley Kendall says:

    Fun quiz! It took me 97s to code it in php, then I ran my script on the command line just to test it out. 3 min 12s after fixing up a few areas.

  12. Fun and easy.

    Took me about 20-40 seconds (no stopwatch, but under a minute) in perl with Data::Dumper output. Another minute to actually code the requested output just because that required actual typing. I didn’t do the pluralization, but that wouldn’t have taken longer than another 30 seconds or less.

    I’d probably do the solution the same way in PHP, but it would require looking up primitives and such. Of course, I’m not currently looking for a job.

  13. Charles Zhou says:

    10 minutes first time… and then I removed my code and started again with the same code, 5 minutes…

  14. Jonah Lang says:

    I just though this was interesting, I’m only a teenager and I only code a little on weekends outside of school. I got it in about a minute, my friend is taking College Computer Science and just plain couldn’t. I’m also curious, how many people realized it said “1 letter” and “2 letters”. It’s not a hard thing to add but still…

  15. West Boy says:

    About 3 min with Perl.

  16. Will Martin says:

    I chose the last bullet point as my sample text.

    Once I got to the actual coding, it took 3 minutes to produce a PHP script that would do this.

    But it also took me 4 minutes to figure out whether punctuation is supposed to count as a letter, decide that it didn’t, experiment with stripping it out with a regex, start checking regex syntax, and then wind up stripping out the punctuation manually because I was running out of time. XD

  17. Dan says:

    I have the same question as Tim Chase.
    For example the word “can’t”
    Is it a 5,4 or a 3 letter word?

  18. Sharon Stone says:

    I love your job description and really with that I was able to apply for this job.

  19. Rules clarification — I assume I can google and consult online references?

  20. About 10 minutes with Python which I write only occasionally for data processing, I had to refer to some online references regarding syntax. My primary languages at the moment are c/c++ but figured python was more appropriate for this task as it has string processing functions in the standard library.

  21. I chose the last bullet point as my sample text.

    Once I got to the actual coding, it took 3 minutes to produce a PHP script that would do this.