There are six cases for the characteristic polynomial $\;p(x)\;$ and for the minimal one $\;m(x)\;$:
$$\begin{align*}\bullet&p(x)=(x-a)(x-b)(x-c)=m(x)\;,\;a,b,c\;\;\text {different. In this case the matrices are diagonalizable:}\\
\begin{pmatrix}a&0&0\\0&b&0\\0&0&c\end{pmatrix}\\{}\\
\bullet&p(x)=(x-a)^2(x-b)=m(x)\;,\;\;a\neq b. \;\text{In this case, the JCF for both}\\
\text{ matrices is }\\{}\\\begin{pmatrix}a&1&0\\0&a&0\\0&0&b\end{pmatrix}\\{}\\
\bullet&p(x)=(x-a)^2(x-b)\;,\;\;m(x)=(x-a)(x-b)\;,\;\;a\neq b. \text{ Here, the JCF}\\
\text{in both cases is}\\{}\\\begin{pmatrix}a&0&0\\0&a&0\\0&0&b\end{pmatrix}\\{}\\
\bullet&p(x)=(x-a)^3...\text{Check the three cases for}\;\;m(x)\end{align*}$$
Let $k$ be an algebraically closed field.
Facts: Let $M$ be a matrix with coefficients in $k$. Then $M$ is conjugate to a block-diagonal matrix where each block is a Jordan block. These blocks, up to reordering, classify the conjugacy classes.
Moreover, let $\lambda$ be an eigenvalue of $M$.
Then
- the number of Jordan blocks corresponding to $\lambda$ is the dimension of the eigenspace;
- the size of the largest block corresponding to $\lambda$ is the multiplicity of $\lambda$ in the minimal polynomial;
- the sum of the sizes of the blocks corresponding to $\lambda$ is the multiplicity of $\lambda$ in the characteristic polynomial.
Therefore, it is enough to look for the smallest integer $N$ such that there are an integer $k$, and two different $k$-tuples of integers $(n_1,\cdots,n_k)$ and $(m_1,\cdots,m_k)$ such that:
- $n_1\geq \cdots \geq n_k \geq 1$ and $m_1\geq \cdots \geq m_k \geq 1$;
- $\sum^k_{i=1} n_i = \sum^k_{i=1} m_i = N$;
- $n_1 = m_1$;
and to form two matrices with only one eigenvalue having Jordan blocks of sizes $(n_1,\cdots,n_k)$ and $(m_1,\cdots,m_k)$.
It is easily seen that the smallest $N$ is $7$, and that examples of tuples are $(3,3,1)$ and $(3,2,2)$.
An example of a couple of two matrices is the following:
$
\begin{pmatrix}
1&1&0&0&0&0&0\\
0&1&1&0&0&0&0\\
0&0&1&0&0&0&0\\
0&0&0&1&1&0&0\\
0&0&0&0&1&1&0\\
0&0&0&0&0&1&0\\
0&0&0&0&0&0&1\\
\end{pmatrix}$ and
$\begin{pmatrix}
1&1&0&0&0&0&0\\
0&1&1&0&0&0&0\\
0&0&1&0&0&0&0\\
0&0&0&1&1&0&0\\
0&0&0&0&1&0&0\\
0&0&0&0&0&1&1\\
0&0&0&0&0&0&1\\
\end{pmatrix}.$
Best Answer
Before proving $AB$ and $BA$ have the same characteristic polynomials show that if $A_{m\times n}$ and $B_{n\times m} $ then characteristic polynomials of $AB$ and $BA$ satisfy following statement: $$x^n|xI_m-AB|=x^m|xI_n-BA|$$ therefore easily conclude if $m=n$ then $AB$ and $BA$ have the same characteristic polynomials.
Define $$C = \begin{bmatrix} xI_m & A \\B & I_n \end{bmatrix},\ D = \begin{bmatrix} I_m & 0 \\-B & xI_n \end{bmatrix}.$$ We have $$ \begin{align*} \det CD &= x^n|xI_m-AB|,\\ \det DC &= x^m|xI_n-BA|. \end{align*} $$ and we know $\det CD=\det DC$ if $m=n$ then $AB$ and $BA$ have the same characteristic polynomials.