Solution to the programming assignment of Algorithm I week 4, on Coursera