Consider the abelian free group $G = \mathbf{Z}^n$ of rank $n$ and a finite subset $A \subset G \setminus \{0\}$. Since $G$ is residually finite, there is a subgroup $H \subset G$ such that $A \cap H = \emptyset$. Call such a subgroup optimal if it has minimal index in $G$.
Is there an efficient algorithm which computes an optimal subgroup $H$? By efficient I mean polynomial complexity in $n$ and $\mathrm{Card}\,A$.
What happens in the nonabelian case ($G$ is a nonabelian free group)? I think it should be more difficult. Is there at least an upper bound for the index of a normal subgroup $H$ such that $A \cap H = \emptyset$?