October 30, 2008

One of my Favorite Interview Questions

Filed under: Programming, Technology — dave @ 1:34 pm

This was stolen from a hiring manager with Microsoft Office when I went through one of the strangest interview loops of my life. Maybe I’ll talk about that another time, but suffice it to say that if another multinational technology company tries to hire me they shouldn’t try to do it in an office park in Las Colinas (Dallas suburb) in a room with no windows under absurd “This offer expires at the door” conditions. But I don’t want to talk about the past, I want to share a pretty mind bending interview question. If you’ve found this because I’m going to be interviewing you, please mention that you found this entry. I will be impressed that you did research in advance on your interviewer.

As with all good interview questions this one is best done in C. Imagine a singly-linked list who’s data is a pointer to another node in the list or is null. So you’ve got something like:

struct Node {
	Node* next;
	Node* data;
}

Write a function that when passed a linked list makes a deep copy. By which I mean that if you had the following

Node Next Data
A B C
B C null
C null C

the function would return:

Node Next Data
D E F
E F null
F null F

Well, a pointer to D, but you knew that already. Writing any function that successfully implements the problem description is passing, but the bonus points come when you do it without using any additional memory (with the obvious exception of the new Nodes that need to be created). To be considered all answers must be in linear time (multiple iterations of the list are acceptable, but it should be a constant number of times, but you knew that when I said linear time)

Polytechnical

Filed under: Programming, Technology — dave @ 1:14 pm

Operating Systems used in the last two weeks:

  • OS X (Leopard)
  • Windows (XP)
  • Linux (Ubuntu Silly Something)

Programming Languages used in the last two weeks:

  • Java
  • Objective-C (iPhone)
  • Python (dinky little script for Austin Stone, but still)
  • PHP (ASCC again)
  • Ruby
  • VB.NET (sorta, was used while conducting an interview)

I don’t know what the cost in depth is when trying to stay current in a number of different technologies, but it does make me keenly aware of which technology space I’m in. Objective-C ticks me off when I need to manage my own memory (especially when there’s so little of it). Java when I deal with hashtables or delegates which are so wonderful in other languages. PHP when I have to look at it. VB when I think about arrays.

I need to get some time in on C# here before too long. I’ve heard there’s a 800 character long regular expression that can convert Java 1.4 into C# 2.0 and vice versa, but there’s stuff like LINQ that I’d like to get my hands on.