think-cell interview question

Solve a problem in C++ while making sure it will pass all case.