solution for problem d