Full threadrcheu·This is the shortest common supersequence problem (https://en.wikipedia.org/wiki/Shortest_common_supersequence_...). It's NP-hard if you include repeating numbers; there's no simple changes to make your solution work in that case.View on HN