week 4 solution algorithm