Partial solution of week2 of algorithm