a-"maze"-ing

Can everyone please discuss the logic for this problem. I find the submissions a bit difficult to understand.

//