Ctrl K

Pairs and Leftovers

Easy
A cloakroom has a pile of tags whose codes are listed in the array codes. Tags with the same code can be clipped together in pairs; each tag belongs to at most one pair. Clip together as many pairs as possible. Return a two-element array: the number of pairs formed and the number of tags left without a partner.
Example 1
codes=[7, 3, 7, 5, 3, 7] → [2, 2]

Pairs: two 7s and two 3s. The third 7 and the 5 are left over, so the answer is [2, 2].

Example 2
codes=[0, 0, 0, 0] → [2, 0]

Four equal numbers make two pairs with nothing left.

Example 3
codes=[12] → [0, 1]
Constraints
  • 1 ≤ len(codes) ≤ 100
  • 0 ≤ codes[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
codes=[7, 3, 7, 5, 3, 7]
Expected
[2, 2]

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