An efficient method for solving a class of nonlocal boundary value problems and error estimate