Program exercise of Algorithm class from Coursera