Solution (source code)

= Solution

For $n\ge3$, extend the restriction of the <continuous function> $f$ to $[1/n,1-1/n]$ to a <continuous function> $f_n$ on $[0,1]$ by making it constant on each of the two remaining intervals. The <Weierstrass approximation theorem> supplies a <polynomial> $P_n$ with $\|P_n-f_n\|_{\infty,[0,1]}<1/n$. Every <compact set> $K\subset(0,1)$ is eventually contained in $[1/n,1-1/n]$, where $f_n=f$. Hence $\sup_K|P_n-f|<1/n$ eventually. This proves \b[uniform convergence on every compact subset], without assuming any endpoint limits of $f$. The first two <polynomials> can be chosen arbitrarily.