That's not the answer I get. Let's assume that the rank of $A$ is $r$. Select a basis for $k^n$ such that $k^n\cong W_1\oplus V_1$, where $W_1=\operatorname{ker}(A)$ and $A$ restricted to $V_1$ is an isomorphism with the image of $A$. Now select a basis for $k^m$ such that $k^m\cong W_2\oplus V_2$, where $V_2=\operatorname{Im}(A)$. With respect to these bases, $A$ looks like
$$
\begin{pmatrix} 0 & 0\\ 0& A_{22} \end{pmatrix}
$$
where $A_{22}$ is an $r\times r$ block matrix with determinant nonzero. Suppose we have the special case where $W=W_1$. Then a $B$ satsifying what you want looks like
$$
\begin{pmatrix} 0 & B_{12}\\ B_{21} & B_{22} \end{pmatrix}.
$$
But, the dimension of the set of such matrices is $r(m-r)+r(n-r)+r^2$, which is not the same as $(n-r)(m-r)$.
EDIT: With the added information and the assumption the book is asking for the codimension of the subspace of matrices, here is an answer. Everything is as above, but the rank of $A$ may not be $r$. Thus $A_{22}$ will be a block matrix of size $s\times s$. Adjust accordingly for $B_{12}$, $B_{21}$, and $B_{22}$. Then the dimension we are looking for is the dimension of the block matrix $0$, which is exactly what is asked.