Official solution
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 = \[{1 \over 2}\]
\[\therefore\] 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)\]
\[ = {\left[ {{3_{{C_0}}}{{\left( {{1 \over 2}} \right)}^3}} \right]^2} + {\left[ {{3_{{C_1}}}{{\left( {{1 \over 2}} \right)}^3}} \right]^2} + {\left[ {{3_{{C_2}}}{{\left( {{1 \over 2}} \right)}^3}} \right]^2} + {\left[ {{3_{{C_3}}}{{\left( {{1 \over 2}} \right)}^3}} \right]^2}\]
\[ = {\left( {{1 \over 2}} \right)^6}\left[ {1 + 9 + 9 + 1} \right]\]
\[ = {{20} \over {64}}\]
\[ = {5 \over {16}}\]