(a)
\begin{equation}
G(x,y,t) = \frac{1}{2 \sqrt{k \pi t}} e^{\frac{-(x-y)^2}{4kt}}\
\end{equation}
\begin{equation*}
u(x,t) = \int_{-\infty}^{\infty} G(x,y,t)g(y)dy \\
= \int_{-\infty}^{0} G(x,y,t)g(y)dy + \int_{0}^{\infty} G(x,y,t)g(y)dy \\
\end{equation*}
Let $-y = z$,
$$ = \int_{\infty}^{0} G(x,-z,t)g(-z)(-dz) + \int_{0}^{\infty} G(x,y,t)g(y)dy$$
We have Dirichlet boundary condition so g(z) is odd;$ g(-z) = -g(z).$
\begin{equation*}
= -\int_{\infty}^{0} G(x,-z,t)g(z)dz + \int_{0}^{\infty} G(x,y,t)g(y)dy\\
= -\int_{\infty}^{0} G(x,-y,t)g(y)dy + \int_{0}^{\infty} G(x,y,t)g(y)dy\\
= \int_{0}^{\infty}\big[G(x,y,t)g(y) - G(x,-y,t)g(y)\big]dy\\
= \int_{0}^{\infty} \frac{1}{2 \sqrt{k \pi t}} \left[ e^{\frac{-(x-y)^2}{4kt}} - e^{\frac{-(x+y)^2}{4kt}} \right] g(y)\,dy.\\
\end{equation*}
(b)
Neumann boundary conditions: $g(y)$ is even $\implies g(x) = g(-x)$
Making the same substitution as in (a), we have:
\begin{equation*}
u(x,t) = \int_{0}^{\infty} \frac{1}{2 \sqrt{k \pi t}} \left[ e^{\frac{-(x-y)^2}{4kt}} + e^{\frac{-(x+y)^2}{4kt}} \right] g(y)\,dy.
\end{equation*}