For $i\in\{1,..,n\}$ let
\begin{gather}
u_i(x)=\prod_{\substack{j=1\\j\neq i}}^n\frac{x-x_j}{x_i-x_j},
\end{gather}
then for $j\in\{1,..,n\}$
\begin{gather}
u_i(x_j)=\delta_{ij}.
\end{gather}
Now let
\begin{gather}
p_i(x)=u_i(x)^2*(2u_i'(x_i)(x_i-x)+1)
\end{gather}
\begin{gather}
q_i(x)=u_i(x)^2*(x-x_i)
\end{gather}
Then by the product and chain rule we have
\begin{gather}
p_i'(x)=2u_i'(x)u_i(x)*(2u_i'(x_i)(x_i-x)+1)-u_i(x)^2*2u_i'(x_i)
\end{gather}
\begin{gather}
q_i'(x)=u_i(x)^2+2u_i(x)u_i'(x)(x-x_i)
\end{gather}
and we see
\begin{gather}
p_i(x_j)=\delta_{ij},\
q_i(x_j)=0,\
p_i'(x_j)=0,\
q_i'(x_j)=\delta_{ij}
\end{gather}
Now
\begin{gather}
f(x)=\sum_{i=1}^na_ip_i(x)+b_iq_i(x)
\end{gather}
is a polynomial of degree at most $2n-1$ which has the desired properties.