Solution (source code)

= Solution

If $L/K$ is Galois, form the norm polynomial
$$
F(X)=\prod_{\sigma\in\operatorname{Gal}(L/K)}\sigma(f)(X).
$$
The Galois group permutes the factors, so $F\in K[X]$. Since the identity factor is $f$, taking $g=F/f\in L[X]$ proves the claim.

If $L/K$ is merely finite separable, place it in a finite Galois closure $M/K$ and use the same product over $\operatorname{Gal}(M/K)$. It gives $F\in K[X]$ divisible by $f$ in $M[X]$. Polynomial division of $F$ by $f$ uses only coefficients in $L$, and the remainder is zero, so the quotient $g=F/f$ actually lies in $L[X]$. It is nonzero and satisfies $fg=F\in K[X]$.