think-cell interview question

Write a function in C++ that implements a given functionality.