Ctrl K

Two Halves Without Repeats

Easy
You are given an integer array items of even length. Distribute all of its elements into two groups of equal size (len(items) / 2 elements each) so that within each group all numbers are distinct. Return True if this is possible and False otherwise.
Example 1
items=[3, 7, 3, 9] → True

For example [3, 7] and [3, 9]: each half holds distinct numbers.

Example 2
items=[5, 5, 2, 5] → False

There are three 5s but only two halves, so one half is bound to get two of them.

Example 3
items=[8, 8] → True
Constraints
  • 2 ≤ len(items) ≤ 100
  • len(items) is even
  • 1 ≤ items[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyValues One Apart EasyEven Piles of Cards EasyMatching Domino Tiles EasyWords From Letter Tiles Easy
loading Python…
Input
items=[3, 7, 3, 9]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.