Suppose the youngest dwarf is $x$ years old. The sum of the ages of
the youngest three is $x+(x+1)+(x+2)=3x+3$, and the sum of the ages
of the oldest three is $(x+4)+(x+5)+(x+6)=3x+15$.
We know that $3x+3=42$, so $3x+15=42+12=54$.
This problem is taken from the UKMT Mathematical Challenges.