Goldman Sachs Interview Question

write cpp code on paper, synthetically correct and compile-able.