Microsoft interview question

Similar to Rotten Oranges problem