We can show that it's $2n-1$ by induction. For $n=2$ we have the word $aba$, and it's clear that we can't continue to add letters. Assume we have shown the maximal length to be $2k-1$ for $k<n$. Now we can only work with $n>2$.
First assume that each letter appears at least $3$ times. Then from the word we can extract a subword using only the first $n-1$ letters and satisfying the condition, which has length at least $3(n-1)>2n-1$ because $n>2$, but this contradicts the induction hypothesis. There is, thus, a letter $a$ which appears at most twice. Now disregard $a$ from our word. What we get is a word using only $n-1$ letters and satisfying the condition. It must then be $\le 2(n-1)-1=2n-3$. This, together with the fact that $a$ appears at most twice, shows that the length of our word on $n$ letters is $\le 2n-3+2=2n-1$.
We can construct the example $a_1,a_2,\ldots,a_n,a_{n-1},\ldots,a_1$ in order to show that $2n-1$ is attainable.