Determine if a valid merged array of two arrays exists

Problem Given two arrays of unique numbers, determine whether a valid merged array arr3 exists such that both input arrays appear as subsequences of it, with all elements globally unique across the merge.

Input / Output

  • Input: two arrays arr1 and arr2 of unique numbers (values may overlap between the two arrays).
  • Output: boolean — whether such a merge exists.

Constraints

  • Elements within each array are unique; the relative order within each array must be preserved in the merge.
  • N = total distinct elements; the ordering constraints define the edges.

Example

  • arr1 = [1,2,3], arr2 = [2,4] → true (e.g. 1,2,3,4 keeps both as subsequences).
  • Constraints that force a before b in one array and b before a in the other → false (contradictory ordering).
asked …
LeaderboardSalaryAccount