Amazon Interview Question

Algorithm question: To print n by m dimensional matrix in spiral way.