NextXAP interview question

Coding assignment is tricky