Apple interview question

Implement functions in C++ library, then optimize them (if possible).