Field Trip May Challenge 2013

May 2013 Challenge field Trip problem.

Problem statement here

Getting a runtime error for this code : My code here

The code runs properly and gives correct output on my computer. But getting a runtime error on submisssion

Can it be memory exceeded error?

//