Let $m,n$ be positive integers, $m,n>1$ and $X = \{(x_1,x_2, ..., x_m) \in \mathbb{Z}^m :1 \le x_i \le n, \forall 1 \le i \le m\}$.

$A$ and $B$ are two disjoint subsets of $X$, such that if $a \in A$ and $b \in B$ then $a$ and $b$ differ in at least $k$ positions (i.e. $a=(a_1,a_2, ..., a_m)$, $b=(b_1,b_2, ..., b_m)$ and there are at least $k$ values $i$ such that $a_i \ne b_i$).

What conditions should $|A|$ and $|B|$ satisfy?

Given that there are positive integers $r, s$ satisfying $|A| \ge r$ and $|B| \ge s$, what is the miminimum value $n$ could have as a function of $k,m,r,s$?

For example, let $m=2$, $X = \{(x_1,x_2) \in \mathbb{Z}^2 :1 \le x_i \le n, \forall 1 \le i \le 2\}$.

If $k=1$ then the relation $|A|+|B| \le n^2$ is sharp.

If $k=2$ it's not hard to see that the following relation holds and it's sharp: $\sqrt{|A|} + \sqrt{|B|} \le n$ (note that if $A_{1}$ is the set of the possible values for $a_1$, and defining $A_2$, $B_1$, $B_2$ in the same way, one has $|A_1|+|B_1| \le n$ and $|A_2|+|B_2| \le n$, where $|A| \le|A_1||A_2|$ and $|B| \le|B_1||B_2|$).

However the problem becomes significantly harder even for $m=3$.

Does anyone know any reference where this problem has been studied or know how to proceed in the general case?

I'm interested on any known results, even for small values of $m$, such $m=3$ or $m=4$.