shortened problem 3 algorithm