find the smallest positive integer $n$ so that there exist $n\times n$ matrices $A,B$ with $(AB)^k = 0$ and $(BA)^k\neq 0$ 
For any positive integer k, find the smallest positive integer $n$ so that there exist $n\times n$ matrices $A,B$ with $(AB)^k = 0$ and $(BA)^k\neq 0$.

I know that by the rank nullity theorem, for any linear map $T : V\to W$ between finite-dimensional vector spaces $V$ and $W, \mathrm{rank}(T) + \mathrm{nullity}(T) = \dim V.$ Also, for any matrices $A,B, \det(AB) = \det(A)\det(B)$ and $\mathrm{rank}(AB) \leq \min\{\mathrm{rank}(A),\mathrm{rank}(B)\}, \mathrm{rank}(A+B) \leq \mathrm{rank}(A) + \mathrm{rank}(B).$ Also, if $M_n(\mathbb{R})$ denotes the ring of matrices of size $n\times n$ with real entries, then $M_n(\mathbb{R})$ is commutative for $n=1$ and noncommutative for $n > 1$ (for instance we have for $n = 2$ that $\begin{pmatrix}1 & 0\\
0 & 0\end{pmatrix}\cdot \begin{pmatrix}0 & 1\\
0 & 0\end{pmatrix} = \begin{pmatrix}0 & 1\\
0 & 0\end{pmatrix}\neq \begin{pmatrix}0 & 0\\
0 & 0\end{pmatrix} = \begin{pmatrix}0 & 1\\
0 & 0\end{pmatrix} \cdot \begin{pmatrix}1 & 0\\
0 & 0\end{pmatrix} $. For the general case of $n > 2,$ we can consider the following two matrices $A = \begin{pmatrix}1 & O_{1\times (n-1)}\\
O_{(n-1)\times 1} & O_{(n-1)\times (n-1)}\end{pmatrix}, B = \begin{pmatrix} O_{1\times (n-1)} & 1\\
O_{(n-1)\times 1} & O_{(n-1)\times (n-1)}\end{pmatrix}$ where $O_{m\times n}$ denotes the $m\times n$ zero matrix ($AB$ has a $1$ in row 1, column n while $BA$ is the zero matrix). There is also the Cayley Hamilton theorem, which states that the characteristic polynomial of any matrix evaluated at that matrix equals the zero matrix. I also know that if $A$ is a matrix such that $A^2$ has rank k = rank A, then $A^n$ has rank k for all $n\ge 1$.
$n=1$ will never work for any $k$ since $M_1(\mathbb{R})$ is commutative. Also neither $A$ nor $B$ can be in the center of $M_n(\mathbb{R})$ for otherwise $AB=BA\Rightarrow (AB)^k = (BA)^k.$  For $k=2,$ we need to find some $n$ so that $(AB)^2 = 0$ while $(BA)^2\neq 0.$ Supposing $n=2$ works we have $A = \begin{pmatrix}a& b\\
c&d \end{pmatrix}, B = \begin{pmatrix}a_2& b_2\\
c_2&d_2 \end{pmatrix}$ for some real numbers $a,b,c,d,a_2,b_2,c_2,d_2.$ It seems fairly tedious to solve the resulting system of equations to determine the values of $A$ and $B$ directly so there's likely a shorter approach. We need $\det(AB) = 0$ for any $k$.

If $(AB)^k = 0$ then $B(AB)^k A = (BA)^{k+1} = 0$. So $BA$ is nilpotent with nilpotence degree exactly $k+1$. An $n \times n$ matrix is nilpotent iff its characteristic polynomial is $t^n$, meaning its nilpotence degree is at most $n$; this gives that $n \ge k+1$.
Here is a construction showing that we can take $n = k+1$. Take $B$ to be diagonal with entries $\underbrace{1, 1,}_{k \text{ times}} \dots 0$, and take $A$ to be a nilpotent Jordan block of size $k+1$. Then $BA = A$ so $(BA)^{k+1} = 0$ while $(BA)^k \neq 0$, but $AB$ is the nilpotent Jordan block of size $k$ (plus some zeroes) so $(AB)^k = 0$.
