Let x be the number of heads obtained by A, and y be the number of heads obtained by B.
Note that x and y are binomial variable with parameters n = 3 and p = 21
∴ Probability that both A and B obtained the same number of heads is
=P(x=0).P(y=0)+P(x=1).P(y=1)+P(x=2).P(y=2)+P(x=3).P(y=3)
=[3C0(21)3]2+[3C1(21)3]2+[3C2(21)3]2+[3C3(21)3]2
=(21)6[1+9+9+1]
=6420
=165