code for Algorithm on Coursera