A modification of MATLAB's nwalign function requiring linear (rather than quadratic) space