[Example 3.2.5] Let $x_{1}, x_{2}, \cdots, x_{n}$ take values in some interval of length 1, and let
$$
\begin{array}{l}
x=\frac{1}{n} \sum_{j=1}^{n} x_{j}, \\
y=\frac{1}{n} \sum_{j=1}^{n} x_{j}^{2} .
\end{array}
$$

Find the maximum value of $f=y-x^{2}$.
We first calculate $f=y-x^{2}$. In the calculation, as in the previous example, we take one of the variables as the main variable, for example, $x_{1}$,
$$
\begin{aligned}
f= & y-x^{2} \\
= & \frac{1}{n} \sum_{j=1}^{n} x_{j}^{2}-\left(\frac{1}{n} \sum_{j=1}^{n} x_{j}\right)^{2} \\
= & \left(\frac{1}{n}-\frac{1}{n^{2}}\right) x_{1}^{2}-\frac{2}{n^{2}}\left(\sum_{i=2}^{n} x_{i}\right) x_{1} \\
& +\left(\frac{1}{n}-\frac{1}{n^{2}}\right) \sum_{i=2}^{n} x_{i}^{2}-\frac{2}{n}\left(\sum_{i=2}^{n} x_{i}\right)^{2}
\end{aligned}
$$

Fixing $x_{2}, x_{3}, \cdots, x_{n}$, then $f$ is a quadratic function of $x_{1}$, and the coefficient of the quadratic term (1) is
$$
\frac{1}{n}-\frac{1}{n^{2}}>0
$$

Since $x_{1}$ takes values in an interval of length 1, we can let $a \leqslant x_{1} \leqslant a+1$.
Because $f$ is a quadratic trinomial in $x_{1}$, its graph is a parabola opening upwards, and its domain is $[a, a+1]$. Therefore, the maximum value of $f$ is achieved at $x_{1}=a$ or $x_{1}=a+1$. That is,
$$
\begin{aligned}
f & =f\left(x_{1}, x_{2}, \cdots, x_{n}\right) \\
& \leqslant \max \left\{f\left(a, x_{2}, \cdots, x_{n}\right), f\left(a+1, x_{2}, \cdots, x_{n}\right)\right\},
\end{aligned}
$$

We then unfreeze $x_{2}$, and similarly,
$$
\begin{aligned}
f & =f\left(x_{1}, x_{2}, \cdots, x_{n}\right) \\
& \leqslant \max \left\{f\left(a, x_{2}, \cdots, x_{n}\right), f\left(a+1, x_{2}, \cdots, x_{n}\right)\right\}, \\
& \leqslant \max \left\{f\left(a, a, x_{3}, \cdots, x_{n}\right), f\left(a, a+1, x_{3}, \cdots, x_{n}\right),\right. \\
& \left.\quad f\left(a+1, a, x_{3}, \cdots, x_{n}\right), f\left(a+1, a+1, x_{3}, \cdots, x_{n}\right)\right\},
\end{aligned}
$$

Unfreezing $x_{3}, x_{4}, \cdots, x_{n}$ in sequence, we know that
$$
f=f\left(x_{1}, x_{2}, \cdots, x_{n}\right)
$$

reaches its maximum value when $x_{1}, x_{2}, \cdots, x_{n}$ each take $a$ or $a+1$.
Let $b=a+1$.
Assume that when $f$ reaches its maximum value, there are $S$ values of $x_{j}$ that take $a$, and $n-S$ values of $x_{j}$ that take $b$. Since
$$
\begin{array}{c}
x=\frac{1}{n} \sum_{j=1}^{n} x_{j}=\frac{1}{n}[S a+(n-S) b], \\
y=\frac{1}{n} \sum_{j=1}^{n} x_{j}^{2}=\frac{1}{n}\left[S a^{2}+(n-S) b^{2}\right], \\
f\left(x_{1}, x_{2}, \cdots, x_{n}\right) \leqslant \frac{1}{n}\left[S a^{2}+(n-S) b^{2}\right]-\left\{\frac{1}{n}[S a+(n-S) b]\right\}^{2} \\
=\frac{S(n-S)}{n^{2}}(b-a)^{2} \\
=\frac{S(n-S)}{n^{2}} .
\end{array}
$$

Since $S(n-S)=-S^{2}+n S$,
when $n$ is odd, $S=\frac{n-1}{2}$, $S(n-S)$ reaches its maximum value $\frac{n^{2}-1}{4}$,
when $n$ is even, $S=\frac{n}{2}$, $S(n-S)$ reaches its maximum value $\frac{n^{2}}{4}$. Therefore, the maximum value of $f=y-x^{2}$ is
$$
f_{\max }=\max _{0 \leqslant s \leqslant n} \frac{S(n-S)}{n^{2}}=\left\{\begin{array}{l}
\frac{1}{4}, \text { when } n \text { is even; } \\
\frac{n^{2}-1}{4 n^{2}}, \text { when } n \text { is odd. }
\end{array}\right.
$$