Solve matrix diagonal and sliding-window statistics | Meta Interview Question