added a solution to problem B