Friday, January 29, 2010

How Difficult is it, Really?

I’ve been using an easier version of my coding question lately, because candidates have struggled so much. First I moved it from C to C# (or Java, if candidates only have a java background). Then I simplified it, a lot. The problem is simple: reverse a string using no outside libraries. This was an introductory-level when I interviewed at Microsoft but now it seems to be advanced!

I’ve had candidates waste 40, 50 lines of code answering this. They usually don’t answer the question at all (they won’t write the full function with signature, or they reverse any words w/o reversing the characters, etc.).

I tried it again last night against .NET 3.x—I wanted to make sure I wasn’t expecting too much--you know, maybe programming has changed while I’ve been in meetings! ;).

I ended up with a small challenge (converting my char[] so it returned a string—kept returning the object type), but other than that, this went really well. 15 lines of code, including curly braces and the step to convert from the input string into a char[] (no error handling; have to get to that next)

Is the question too difficult? Wanna take a stab? Can you beat 15 lines, without using string.Reverse()?

42 comments:

  1. Hi John. Assuming you're attempting to hire programmers, what you're asking is not that difficult. Here's a 10-line Java version (sorry I didn't have C# installed):

    public String reverse(String s)
    {
    assert(s != null);
    StringBuffer buf = new StringBuffer();
    for (int i = s.length() - 1; i>=0; --i)
    {
    buf.append(s.charAt(i));
    }
    return buf.toString();
    }

    It's commonly known that there can easily be differences of 10x in programmer speed / effectiveness, as a Google search for "programmer productivity 10" shows. If a programmer can't handle that request in a couple of minutes, you probably don't want them programming for you.

    At first glance my code above might seem fine, but in reality, it's not. Certain Unicode grapheme's can't fit into a single character (even though Java's char is 32-bits, with the lower 21 representing the actual character). Thus, I'd actually need to check to make sure that each character wasn't one of these two-part graphemes that would need to have the order remain intact. So, maybe it really is a harder question than I thought ;).

    ReplyDelete
  2. Hey Kaleb, good point on the unicode issue. That trips up a lot of people.

    I also agree on the coding speed comment.

    Nicely done and no, it shoudln't be that difficult.

    ReplyDelete
  3. 人生最大的榮耀,不是永遠不敗,而是屢仆屢戰..................................................

    ReplyDelete
  4. 我對自己的信心已超越別人對我的評價..............................

    ReplyDelete
  5. 欣賞是一種美德~回應是最大的支持^^.................................................................                           

    ReplyDelete
  6. 在莫非定律中有項笨蛋定律:「一個組織中的笨蛋,恆大於等於三分之二。」......................................................................

    ReplyDelete
  7. 當一個人內心能容納兩樣相互衝突的東西,這個人便開始變得有價值了。............................................................

    ReplyDelete
  8. 生存乃是不斷地在內心與靈魂交戰;寫作是坐著審判自己。. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    ReplyDelete
  9. 世間事沒有一樣沒有困難,只要有信心去做,至少可以做出一些成績。..................................................

    ReplyDelete
  10. 做好事,不需要給人知道,雖然只是一件微不足道的事,但我相信,這會帶給我快樂。..................................................

    ReplyDelete
  11. 感謝分享~希望有更多的好文章分享給大家.................................[/url]...............

    ReplyDelete
  12. John: I'm writing from STP but didn't quickly have your email. Would you mind emailing me?
    yhamilton@redwoodco.com

    ReplyDelete
  13. Your Blog is one of the best top 100 software testing blogs listed in this article:
    http://www.testingminded.com/2010/04/top-100-software-testing-blogs.html
    but for me, it's just one of the best! Keep the great work!
    ------------------
    If you plan to go in Cameroon, please visit: Offres d'emploi au Cameroun

    ReplyDelete