Matic Interview Question

Implement C++ challenge, cannot share here.