TITLE: Are groups with all the same Hom sets already isomorphic?
QUESTION [14 upvotes]: I was thinking about the following: Say we got two groups $A$ and $B$, and we know that for any group C, there is a bijection
$$Hom(A,C) \to Hom(B,C).$$
Are $A$ and $B$ already isomorphic?
If the family of bijections was natural in $C$, this follows from Yoneda's lemma. But does it hold anyway without naturality, just from the cardinalities? I would suspect no but in simple cases (finitely generated). I'd like to hear any thoughts on how to come up with a proof or counterexample.
Also, does the answer change when we consider the contravariant case with an identification $Hom(C,A) \to Hom(C,B)$?

REPLY [6 votes]: If there is a surjective homomorphism $\rho:A \rightarrow B$ then, for any group $C$,  $\alpha \mapsto \alpha \circ \rho$ is an injective map ${\rm Hom}(B,C) \to {\rm Hom}(A,C)$.
So, for any pair of groups $A$ and $B$ which are isomorphic to homomorphic images of each other, we have $|{\rm Hom}(A,C)| = |{\rm Hom}(B,C)|$.
There are examples of pairs of non-isomorphic finitely generated groups with this property. An example is given in Theorem 3 of the well-known paper "Some two-generator one-relator non-Hopfian groups" by Baumslag and Solitar
$$A = \langle a,b \mid a^{-1}b^2a=b^3 \rangle,$$
$$B = \langle c,d \mid c^{-1}d^2c=d^3, ([c,d]^2c^{-1})^2=1 \rangle.$$