Split the Array - Problem
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 / 2nums1should contain distinct elementsnums2should also contain distinct elements
Return true if it is possible to split the array, and false otherwise.
Input & Output
Example 1 — Basic Valid Split
$
Input:
nums = [1,1,2,2]
›
Output:
true
💡 Note:
We can split into [1,2] and [1,2]. Both groups have distinct elements.
Example 2 — Impossible Split
$
Input:
nums = [1,1,1,1]
›
Output:
false
💡 Note:
Element 1 appears 4 times. Cannot split into two distinct groups of size 2.
Example 3 — Mixed Frequencies
$
Input:
nums = [1,1,2,3]
›
Output:
true
💡 Note:
Can split into [1,2] and [1,3]. Each group has distinct elements.
Constraints
- 2 ≤ nums.length ≤ 100
- nums.length is even
- -100 ≤ nums[i] ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [1,1,2,2] of even length
2
Process
Check if we can split into two distinct groups
3
Output
Return true if splitting is possible
Key Takeaway
🎯 Key Insight: If any element appears more than twice, splitting into two distinct groups is impossible
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code