Split the Array

You are given an integer array nums of even length. You have to split the array into two parts nums1 and nums2 such that:

  • nums1.length == nums2.length == nums.length / 2.
  • nums1 should contain distinct elements.
  • nums2 should also contain distinct elements.

Return true if it is possible to split the array, and false otherwise.

Example 1
Inputnums = [1,1,2,2,3,4]
Outputtrue
One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].
Example 2
Inputnums = [1,1,1,1]
Outputfalse
The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1], so both parts do not contain distinct elements.

Constraints

  • 1 <= nums.length <= 100
  • nums.length % 2 == 0
  • 1 <= nums[i] <= 100

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate