P(A and B get same number of heads) = P(A and B both get 0 head ) + P(A and B both get 1 head) + P(A and B both get 1 head) + P(A and B both get 1 head) .................(1)

NowP(A and B both get 0 head ) :^{3}C_{0} (1/2)^{3} . ^{3}C_{0} (1/2)^{3} [Since A and B toss 3 coins each separately so they need to be considered separate events.Also since it is a coin toss problem so it considers the requirements of binomial distribution and hence we apply this formula but separately for A and B and multiplying them since both of them will occur hence follows multiplication principle and also A and B are separate events as mentioned earlier]

= 1/64

SImilarly P(A and B both get 1 head ) : ^{3}C_{1} (1/2)^{3} . ^{3}C_{1} (1/2)^{3}

^{ }= 9/64

SImilarly P(A and B both get 2 heads ) : ^{3}C_{2} (1/2)^{3} . ^{3}C_{2} (1/2)^{3}

^{ }= 9/64

SImilarly P(A and B both get 3 heads) : ^{3}C_{3} (1/2)^{3} . ^{3}C_{3} (1/2)^{3}

^{ }= 1/64

Hence from (1) , we have :

P(A and B get same number of heads) = 1/64 + 9/64 + 9/64 + 1/64