Advertisement

Question about programming tests...

Started by February 25, 2009 12:41 AM
17 comments, last by Extrarius 15 years, 8 months ago
That is, the sort that you are asked to take by a prospective employer so that they can evaluate you. I've taken all sorts of these. Some of them have several questions, some of them have just one challenge. Some of them are timed, some aren't (but they want to know how long it took you to complete it). I just took one, and I'm not going to lie to you, it took me 8.5 hours to complete it. It was a single challenge: given a set of Scrabble tiles, and a Scrabble board that has some words laid down already, find the optimal move, i.e. the move you can make that will score the highest points. It's especially challenging because, as Scrabble players know, you can score extra points if the tiles you lay down help form more than one new word on the game board. I don't know, is that normal? The problem was exacerbated by the fact that the dictionary they provided (a global array of char*) wasn't perfectly alphabetized -- it was close, but there were a few mistakes. In any case, I wrote a binary search function for quick lookups into the dictionary, since I would have to do those often, but since there were some mistakes in the dictionary alphabetization, and I wasn't clear on whether I was allowed to modify the dictionary in-code, I had to create an in-place quicksort that I would run at the very beginning. In any case, it was really difficult to track down this bug in the first place, because at first sight, the dictionary looked sorted perfectly and I didn't think to double-check it. Edit: I also wanted to mention that the algorithm that I settled on takes maybe 1/8th of a second to complete, i.e. fast enough that it can do several per second, but slow enough to cause a noticeable frame rate hitch if not done asynchronously. I can probably get a more accurate time, as I'm just basing this off the fact that it took about 0.5 seconds to complete 4 puzzles. I'm just curious what they're going to think about me taking 8.5 hours to write an algorithm that solves the above puzzle in 0.125 seconds >_< Probably not good, eh? [Edited by - CDProp on February 25, 2009 1:19:57 AM]
Well, they'll probably think that you'll spend a lot of time to fix something properly and efficiently. When they give you a task, they can expect perfection. {That would be my analysis}

As a different example: I would probably have written code to solve your problem in half an hour tops. On the other hand, I wouldn't be surprised if it would take my algorithm well over an hour to complete; I like brute-force and recursion. *laughs* Think about what they'd think about /that/ ;)
Advertisement
It depends if it's a "do you know C++" test or a "do you know how to solve problems" test. You could write a very quick brute force solution first... in fact this is normally needed to test correctness of your clever algorithm. And then try something better, or write why brute-force is bad and the kind of things you might try with more time.

Asking them what they're looking for is always wise though. Maybe they only want to hire people with lots of algorithm skills... dynamic programming, graph theory, etc.
I dont think its uncommon for them to give you a task that is extremely difficult, and they dont necessarily expect you to solve it. They just want to get a glimpse of you thinking process. So I hope you showed all the steps you took.

I remember doing one interview where the company gave me a 'problem' to solve, and it turned out that the 'problem' was the company's entire reason for existance. It was a problem that 6 to 8 people had been working on for 3 years, so they obviously didnt expect me to solve it in an hour.
I don't like those kinds of tests that are far removed from the actual work you're actually going to do (I'm assuming you're not writing TopCoder solutions at this job).

I had to hire a programmer several months back, and the most difficult part of the job technically was going to be writing very complex SQL queries. So I made up a schema that was dumbed down from our actual production schema, then wrote up a test of ten queries to write against it, in increasing order of complexity.

It was obvious when someone was BSing a claim of "8 years" of SQL experience on their resume, when it took them four hours to (poorly/incorrectly) complete eight of the ten problems. Instead, I ended up hiring a fresh graduate who finished most of them in a couple minutes, then asked if he could use Google/Wikipedia.

That gave me a much better idea of the person I'm going to hire than a Scrabble puzzle or a "you're a frog in a blender that's going to turn on in 30 seconds" mind game.
My three favorite questions I ask at interviews are,

  1. Two-second question: implement the factorial function recursively. If you spend more than a minute thinking about this, bye-bye.

  2. Practical question: implement heap sort.

  3. Design question: you have a model-view-controller design for a website. You want all users to have different e-mail addresses to prevent people from mistakenly registering twice. Where (model, view, controller) do you write that check?
Advertisement
Quote: Original post by ToohrVyk
My three favorite questions I ask at interviews are,

  1. Two-second question: implement the factorial function recursively. If you spend more than a minute thinking about this, bye-bye.

  2. Practical question: implement heap sort.

  3. Design question: you have a model-view-controller design for a website. You want all users to have different e-mail addresses to prevent people from mistakenly registering twice. Where (model, view, controller) do you write that check?


Whats the answer to number 3? I would say all 3...
Model.

ToohrVyk: I very rarely implement sorting routines myself. Would you allow Wikipedia access so I can remind myself of the algorithm?

[edit] Read your linked blog entry, nevermind.
I was taught that the proper way to enforce a rule involves all 3 parts of the MVC.

You need to do it in the model, eg in the database you would have a UNIQUE property on the email address field, or whatever the detailed requirements are.

You need to enforce it in the controller, meaning making a call to the database to see if the email address already exists, before attempting to insert it. If its already there, you can do some custom error handling such as generating a message asking if they forgot their password.

You need to do it in the view as well, providing instructions that email addresses should be unique, and support for message boxes to pop up (or whatever) informing users when an email address is already in use.

Where possible, its smart to enforce rules in the view (interface), for eg using &#106avascript. For things like entering dates, you can use &#106avascript to check that its a valid date, for speed and convienience. However you still need to enforce the same rule in the controller, because &#106avascript can be circumvented. And you enforce it in the database as well, because databases are happiest when they know everything about the data they're supposed to hold.
Your view (web page) makes a call to the controller (business logic code on the server) saying the user has directed it to insert a new user. The controller performs any manipulation of the data that may be required, and then sends that data to the model (code which makes queries against the database) asking it to insert it into the database. The model then checks that all the data is valid, including checking whether the email address is duplicated. It responds to the controller that it can't insert, and why. The controller then informs the view layer that it was unable to insert the user, and why.

You're right about validating simple user input stuff in the view if possible, but the question was particularly formulated so that it had to be checked at the server.

This topic is closed to new replies.

Advertisement