Solution (source code)

= Solution

The intended orthogonal-<polynomial> convention is \b[$\deg p_k=k$]. An arbitrary <orthonormal basis> without this degree ordering does not satisfy the claim: permuting a standard <basis> can place the nonzero constant <polynomial> last, where it has no <root>[roots] rather than $n+1$. The following proof uses the required degree ordering.

It makes $p_k$ orthogonal to every <polynomial> of degree less than $k$, since $p_0,\ldots,p_{k-1}$ form a <basis> of that lower-degree space. Let $c_1,\ldots,c_r$ be the distinct <root>[roots] in $(a,b)$ at which $p_k$ changes sign, and put $q(x)=\prod_{j=1}^r(x-c_j)$, with $q=1$ if $r=0$. The product $p_kq$ has constant sign on $(a,b)$ except at its finitely many zeros: each sign change of $p_k$ is canceled by that of $q$.

If $r<k$, then $q$ has degree below $k$, so <orthogonality> gives $\int_a^bp_kqw=0$. But a nonzero constant-sign continuous product against the positive weight has a nonzero integral, a contradiction. Thus $r\geq k$. Since $\deg p_k=k$, there are exactly $k$ such <root>[roots], all simple, with no additional endpoint <root>[roots]. In particular
$$
\boxed{p_k\text{ has exactly }k\text{ distinct roots, all in }(a,b).}
$$
This also includes $k=0$, where the <polynomial> is nonzero constant and has no <root>[roots].