So, this is not my home work question, but it is taken from an ungraded homework of the coursera course on algorithms and data structures (which is now complete).
Y
I think this is actually really easy.
Turn the problem into 3-D one to see why the algorithm works. Put the matrix on a table. Pretend there are pillars extending out of each cell and that the height of the pillar is directly proportional to its value. Put a ball on any pillar. Have the ball always fall onto the adjacent pillar that is the lowest altitude until it is at a local minimum.