let b array length n m respectively element common we define new array mathrmmergeab length nm recursively follow if array result array that mathrmmergeemptysetbb mathrmmergeaemptyseta in particular mathrmmergeemptysetemptysetemptyset if array nonempty a_1b_1 mathrmmergeaba_1mathrmmergea_2ldotsa_nb that delete element a_1 merge remain array add a_1 begin result if array nonempty a_1b_1 mathrmmergeabb_1mathrmmergeab_2ldotsb_m that delete element b_1 b merge remain array add b_1 beginning result this algorithm nice property b sorted mathrmmergeab sort for example subroutine mergesort for problem consider procedure acting nonsorted array for example a31 b24 mathrmmergeab2314a permutation array consist n distinct integer 1 n arbitrary order for example 23154 permutation 122 permutation 2 appear twice array 134 permutation n3 4 arrayThere permutation p length 2n Determine exist array b length n element common pmathrmmergeab