Let $D$ be an $n \times n$ diagonal matrix whose distinct diagonal entries are $d_1,\ldots, d_k$, and where $d_i$ occurs exactly $n_i$ times. For the subspace $W$ of $M_{n \times n}(F)$ defined by $W=\{A : AD = DA\}$ prove that $\text{dim}(W) = n_1^2 + n_2^2 +\ldots+ n_k^2$
I know that $A \in W$ must be symmetric, and I can see that if each $d_k$ is distinct and only occurs once, that $W$ has dimension $n$. I also realize that if $D_{ii} = D_{jj}$ then $A_{ji}$ can be anything and $A_{ij}$ can be anything. (that's terrible wording but this question has me so lost), and if $D_{ii} \neq D_{jj}$ then $A_{ij} = 0$ and $A_{ji} = 0$.
I'm not sure how to formalize any of my thoughts on this question at all. It is a homework question that I'd like to understand fully.