solution for problemB