DRW interview question

Difficult programming assignment.