FastPrepUnique Supersequence Merge

Unique Supersequence Merge

Blinkit logoBlinkit● MediumONSITE INTERVIEW

Problem statement

You are given two arrays arr1 and arr2. Each array contains unique numbers.

Return true if there exists an array arr3 such that:

  • arr1 is a subsequence of arr3.
  • arr2 is a subsequence of arr3.
  • All numbers in arr3 are unique.

Otherwise return false.

Function

canMergeUniqueSubsequences(arr1: int[], arr2: int[]) → boolean

Examples

Example 1

arr1 = [2,3,5,1]arr2 = [4,3,5,1,9]return = true

One valid merged array is [2,4,3,5,1,9].

Example 2

arr1 = [2,3,5,1]arr2 = [2,3,1,5]return = false

The first array requires 5 before 1, while the second array requires 1 before 5. Both cannot be true in one unique array.

More Blinkit problems

See Blinkit hiring insights
Saved
public boolean canMergeUniqueSubsequences(int[] arr1, int[] arr2) {
  // write your code here
}
arr1[2,3,5,1]
arr2[4,3,5,1,9]
expectedtrue
Checking account…