optimize problem 20 using map