Recently, I was given a programming problem for a pre-interview job screen.
Implementation
C# interface
- Create a class which implements either the C# or Java interface
- Implement the two methods defined in the interface. FindMaxValue should return the single highest integer. FindTopNValues should return a list of the highest 'n' values in the source list
- Any assumptions or design choices made during the implementation should be documented.
namespace Test { public interface IFindTopValues { int FindMaxValue(int[] values); int[] FindTopNValue(int[] values, int count); } }Test cases
- Describe the test cases which you would implement for this class.
Here's the solution I produced. It uses a C# generic PriorityQueue class. Have a look -- it's useful, reusable code.
Update (2008-05-15): I noticed that Julian Bucknall had a change to his priority queue that ordered entries by priority and time of entry. I decided to update my code to provide the same ability.

Hugh,
Did you get the job? I've been sent out the same test and wonder if the answer you've got is ok. It looks pretty good to me.
Fred
I didn't get the job, actually. And yes, it's a great computer science answer. This solution has the distinct advantage that should you be interested in pulling out more sorted values, you can do so at low cost.
I would not recommend you copy, imitate, or plagiarize this answer. Among other reasons, it would be fairly memorable to anyone who has seen it before.
If I were answering this question again, I'd go for an answer based on LINQ. I suspect that there is more processing in this because LINQ would have to sort the entire array but there are three advantages:
- it's the hot new Microsoft technology and it would show that you are on top of things
- it is dead simple to code and can easily be done in a 1-2 hour time limit
- it is dead simple to test
Chances are, those elements would make the answer desirable to a technical interviewer.
Shame you didn't get the job.
Any LINQ code snippets you could share as I think you might me right about using some new technology?
Fred.
You can look up LINQ and Take() to see the basic approach.