Merge Two Ordered Sequences
Asked at Google
Reported by the problem's creator, not verified
You are given two integer arrays a and b. Within each array the order is a rule: an element must come before every element that appears after it in the same array. A value that appears in both arrays is the same item. Implement can_merge(a, b) to decide whether all distinct values can be laid out in one sequence, each value once, that keeps the order of a and the order of b.
Examples
Example 1
Input: a =
[1,2,3], b =[2,4,5]Output:
trueExplanation: The order 1, 2, 3, 4, 5 keeps 1, 2, 3 in order and 2, 4, 5 in order.
Example 2
Input: a =
[1,6,4], b =[4,1]Output:
falseExplanation:
aneeds 1 before 4 andbneeds 4 before 1, so no single order works.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.