Step 1: Express heterozygosity in terms of allele frequencies.
Let the \(n\) allele frequencies be \(p_1,\ldots,p_n\) with \(\sum_i p_i = 1\).
Under HWE, the expected heterozygosity
\[
H \;=\; 1 - \sum_{i=1}^{n} p_i^2 .
\]
Step 2: Maximize \(H\) subject to \(\sum p_i=1\).
Maximizing \(H\) is equivalent to minimizing \(\sum p_i^2\).
By symmetry/convexity (or by Lagrange multipliers), the sum of squares is minimized when all \(p_i\) are equal:
\[
p_i = \frac{1}{n}\quad \forall i.
\]
Step 3: Evaluate \(H\) at the optimum.
\[
H_{\max} = 1 - \sum_{i=1}^{n}\left(\frac{1}{n}\right)^2
= 1 - n\cdot \frac{1}{n^2}
= 1 - \frac{1}{n}.
\]
Final Answer:
\[
\boxed{\,1-\frac{1}{n}\,}
\]