Goldman Sachs Interview Question

sending the coding challenge first