C++ solution to CTCI