verifying whether or not a combined string is a valid merge using dynamic programming