Job Interview Homework Puzzle in C++