wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> New programming interview question ideas
(Message started by: bryanilee on Jul 15th, 2012, 10:27pm)

Title: New programming interview question ideas
Post by bryanilee on Jul 15th, 2012, 10:27pm
I didn't see an existing thread on this, but I'm a newbie, so I might have missed something - apologies if I did.  :-)

Anyone have ideas for new interview questions for a programming position?

Here's one I was thinking about:
In a simple "alphabetical" sort, you would get this sort order:
a
b
b1
b12
b154
b2
b3
b6

But sometimes you actually want the numerical part to be sorted as a number (and in some newer OS's this is how filenames are sorted):
a
b
b1
b2
b3
b6
b12
b154

Write an algorithm to sort strings in this order.  And in general it would be good to handle multiple numerical portions in strings, so you would want this ordering:
number 1 sub 1 a
number 1 sub 2 a
number 1 sub 12
number 2 sub 12
number 11 sub 1
number 11 sub 2
number 11 sub 12
etc.

----------
What do you think?  Too easy too hard?

Title: Re: New programming interview question ideas
Post by towr on Jul 16th, 2012, 10:29pm
Sounds like a reasonable question.
When you have just an alphabetic part plus a numeric part, you could do a numeric sort on that part first, and then a stable lexical sort. When you can have an arbitrary number of alternating alphabetic and numeric parts you need a slightly different approach (because one string might have more parts than another). But it's not too hard to design a comparison function that correctly compares corresponding parts.

Title: Re: New programming interview question ideas
Post by Grimbal on Jul 17th, 2012, 8:45am
I actually wrote such a function for comparing multi-part version numbers, like 2.17.1123.

You just need to see how far they are equal.  From there on, there are 4 cases, depending if the next character on either side is a digit or not.  If both are digits, compare as numbers the groups of digits that follow on each side.

Title: Re: New programming interview question ideas
Post by zxy112 on Aug 14th, 2012, 9:25pm
something like a modified radix sort may do ... but there shud be a limitation in the alphanum set that needs to be sorted ...



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board