#3046

Split the Array

pupil · 375 · lc easy +23 · verified · 61% accepted · 168 likes · top 61%

Description

Given an even-length integer array nums, determine whether it is possible to partition it into two equal-length subarrays nums1 and nums2 such that:

- nums1.length == nums2.length == nums.length / 2.

- All elements in nums1 are distinct.

- All elements in nums2 are distinct.

Return true if such a partition exists, and false otherwise.

Example 1:

Input: nums = [1,1,2,2,3,4]
Output: true
Explanation: One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].

Example 2:

Input: nums = [1,1,1,1]
Output: false
Explanation: The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.

Code

1
2
3