Apple Interview Question

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