We study nonlocal boundary value problems of the first and second kind for the heat equation with variable coefficients in the differential and difference settings. By the method of energy inequalities, we find a priori estimates for the differential and difference problems.