In a class of 40 students, 18 said they liked apple pie, 15 said they liked chocolate cake and 12 said they did not like either. How many students in the class liked both?
(A) 15
(B) 10
(C) 3
(D) 7
(E) 5
Of the 40 students, 12 did not like either dessert.

Therefore, $40-12=28$ students liked at least one of the desserts.

But 18 students said they liked apple pie, 15 said they liked chocolate cake, and $18+15=33$, so $33-28=5$ students must have liked both of the desserts.

ANSWER: (E)