Amazon interview question

Programming exercise (Python, data structures, I/O)