I was asked to do the first on a whiteboard in a job interview. I was not able to compile or run my code on a computer, I had to debug it just by reasoning out how the source looked. My interviewer was impressed, and pointed out that I paid careful attention to performance:
Reverse a C string in place.
I was later asked to do the same as part of a job application, before my interview. In that case I was permitted to compile and run my code. They also wanted the code to be tested, so I wrote several unit tests.
There are some special cases to consider for complete test coverage. What are they?
This second assignment additionally required me to reverse a constant C string - a "const char *". Because const data items may not be altered, I could not reverse it in place. Instead I had to allocate a buffer for the reversed string then return a pointer to a buffer.
Obviously having the two together in the same code library makes the job of implementing the two together simpler than doing both of them separately. What's the best way to take advantage of their commonality?
Now do both of those things in C++ but instead of reversing C strings, reverse std::string and const STD::string from the Standard Template Library.
The damn iOS autocorrect insists on improperly uppercasing the ISO c++ STD namespace so it becomes the Sexually Transmitted Disease namespace!
When you get this all working, post a diary about the problems you encountered along the way as well as what you did to overcome them. Also post the source. There is a simple Perl script that marks up source code for posting to Scoop, I'll dig t up for you.
--
Mike Crawford for Clark County Commissioner
District 1 North County
mike@communard.org
Paid for by The Communard Party of Washington State