Arm interview question

Programming a complex problem on paper was difficult for me. Think thoroughly before starting on paper.