add merge sorted array with minimum memory codes