Solution (source code)

= Solution

Apply the <Gram-Schmidt process> to $1,x,\ldots,x^n$. The last resulting vector $P_n$ is nonzero, has degree exactly $n$, and is orthogonal to every polynomial in $\operatorname{span}(1,x,\ldots,x^{n-1})$.