I teach a software engineering lab class for Seniors in Computer Science and Engineering (Bachelor's degree). I understand that many companies have interviewees solve simple programming problems on a whiteboard or piece of paper.
I would like to prepare my students for this as they do not normally have to stand in front of a judgmental audience and write programs on a whiteboard. Thus, I am looking for some good questions to ask them.
The question should be answerable in 15-30 minutes, on a whiteboard, by a solid CSE graduate. I am looking for programming questions, not puzzles.
-
Write a function which counts the number of vowels and consonants in a string. Any language you choose.
dacracot : Trick is not to forget upper and lower, non-letters, and finally a null string.Mez : I'd use a regex to substitute the letters, then split it into an array, and get the occurences of my strings :Dmike511 : what about sometimes "Y"? :)From dacracot -
Write pseudo-code that would sort an array using several different algorithms.
Adam Davis : Probably not a 15 minute board question, though. Maybe just bubble sort.From Dan Cramer -
Classic c style string questions:
implement strstr,strrchr, strpbrk, strlen functions and all other string manipulation: Contains, Replace, etc... Performance wise.
implement strtok. Implement it as thread safe.
Knowing pointers is a basic test. Experienced programmer should be able to do it within 15 minutes.
From Yuval Peled -
There are quite a few sites dedicated to this. e.g., http://www.techinterviews.com/. Most of them have puzzle questions, but they also have real technical questions as well. I'd check out those if you want a big list. There are hundreds of good questions in lots of different areas.
From Derek Park -
After years of trying various approaches to this problem in job interviews, I have settled on what I think is the best challenge:
strstr: find the first location of a string in another string.
This is a well-known function across many languages, and can be coded in under fifteen lines. (Anything more is too much for a whiteboard.)
strstr is also perfect because it is just the right level of difficulty: two levels of looping. It sounds like it might be too easy, but it will instantly separate those who can code from those who cannot. In fact, maybe only one in five candidates gets it right without help.
From adum -
Implement a simple FIFO (queue) and LIFO (stack).
Implement a priority queue.
Implement a simple linked list.
Implement a whitespace stripping function - removes leading and/or trailing whitespace from a byte array.
Implement a function to convert a positive number into its hexadecimal equivalent, and then the converse.
Implement atoi.
Write a some code which demonstrates limitations of floating point code.
Write a string compare routine in a recursive function.
Derek Park : Adam, a stack is not a type of queue. Queues are FIFOs.Adam Davis : Not all queues are fifos - a priority queue is still a queue, but is not a fifo. You are correct that stacks are not queues, which is a mistake on my part. Fixed the text. Did someone downvote this just for that one error? Wow, strict types we've got around here!Derek Park : Your text is still confusing. A stack is a LIFO. A queue is not. The standard queue is a FIFO. Priority queues are different from standard queues, and are still not LIFOs.Adam Davis : Doh! I edited incorrectly! My bad...From Adam Davis -
A good one I've used before is a simple question that reveals code reading skills, knowledge of binary, inductive reasoning skills, and communication skills (as the answer is probably not obvious, and questions are encouraged)
What useful question does the following function answer about a number? Yes, it is a useful and distinct quality for a number to have, especially so in computer science. (Please tell them to ask questions and walk themselves through their thought process on the whiteboard)
bool mystery(unsigned int num){ unsigned int other = num - 1; bool result = ((num & other) == 0); return result; }
The answer will be in a comment to this post.
Sufian : This function answers the question: Is this number a power of two? (Bonus points if they realize it is incorrect for the input number 0)From Sufian -
I tend to ask questions that should be solvable within a few minutes so that there is time for Q&A on their implementation. One question I like to ask is:
Write a function that counts the number of bits in a list of integers.
I'm often surprised on how many people have trouble with this.
From Rontologist -
One I use a lot is to write a function that reverses the words in a sentence, excluding punctuation. There are several variations on this by allowing/not allowing built-in methods for string manipulation.
So, the sentence "The quick brown fox" becomes "fox brown quick The".
The more important part of these excercises is to see/hear how the interviewee reasons out the solution. There is usually more than one way to solve the problem none of which are "more right" than any others.
From Scott Dorman -
For OO languages:
Implement a money class that:
- Doesn't suffer from precision loss (big numbers = bad juju in floating point)
- Stores money internally in US dollars
- Implements methods that return the value of money in Euros, Yen, Pounds, etc
Implement a roman numeral class (accepts roman numeral strings or integers, stores the number, returns integer or roman numerals, doesn't have to be perfect (say only for numbers up to C)
From Adam Davis -
Having your students create simple functions on a whiteboard is good practice however I have noticed (at least for the company I work for) when we interview someone the problems they need to solve are much more involved.
The main goal really for us is to see someones approach to an overall problem and how they solved it. For example:
- Implement or design a data base structure for a simple login application
- Given an xml structure, design classes and parsers to consume and manipulate the xml
All not very difficult problems to solve but they help the interviewer learn how the interviewee approaches a problem, cause once the interviewee has finished the problems or has attempted them, we would discuss their design and approach.
Just food for thought, possibly a good exercise would be to have them explain their approach to solving the problem once they have finished. This also gives them a chance to rethink about the problem while they are explaining it and helps reinforce good communication skills.
From JustFoo -
The first time I had to do whiteboard coding in an interview I totally flubbed it. My experience was that I was completely unprepared to write (compilable!) code on a blackboard without practice, and any kind of practice would've been an immense help.
Anything simple,a few loop iterations. The important thing is to make it compilable.
From Steve B. -
Write pseudocode and the sketch of a design for a search engine. What are the parts of the system? How do you define success? What are the different phases of operation?
You can deep-dive into any part of this thing to see if the person answering the question has the chops.
From djsadinoff -
Implement Twitter or iGoogle from scratch, go. (an idea from @rex-m)
From Chris Ballance -
The number one way I eliminate candidates is by very basic SQL experience. To that end I ask a couple of what should be simple SQL questions.
- requires them to know how to do a simple select statement with a where clause.
- requires them to do an inner (and outer) join on two tables
- requires them to update records with a where clause.
Unfortunately, 90% of the so called application programmers out there can't do those queries. I can understand an embedded systems dev not knowing them, but anyone with a modicum of experience doing client / server or web apps should be able to answer them quickly.
Also, I don't even care about exact syntax, as long as they understand the idea.
From Chris Lively -
Here are some I've been asked in interviews:
Write a function that does integer division without using / or %.
Given two nodes in a binary search tree sketch a function that finds their least common ancestor.
"Programming Pearls" by Jon Bentley is a great resource for these types of puzzles. Also "Programming Interviews Exposed" is a good resource.
From MrDatabase -
You may want to try a few problems from Project Euler they're fairly math oriented, but they can be quite challenging and rewarding.
From Zee JollyRoger -
Implement a binary search (presuming a sorted input).
Most people get it wrong the first couple times through - I only ever use an already-written and -verified binary search because I get it wrong usually the first two times, too :)
FM : +1 Just conducted a half dozens interviews. None of the candidates answered the question smoothly. *"Although the basic idea of binary search is comparatively straightforward, the details can be surprisingly tricky."* — Donald Knuth.warren : @FM - in 'Programming Pearls 2d ed', the author notes there was an error in the first edition with regards to binary search - and he is a pro :)From warren
0 comments:
Post a Comment