Matching Pairs
Easy · Counting Warm-ups · Hash Table · Counting
Problem
A pile of n items is described by a list of colour codes. Items of the same colour can be paired up.
Return how many complete pairs the pile contains. Leftover single items are ignored.
Examples
Input: n = 9, items = [10,20,20,10,10,30,50,10,20] Output: 3
Colour 10 appears 4 times (2 pairs), colour 20 appears 3 times (1 pair), 30 and 50 appear once (no pair).
Constraints
- 1 <= n <= 100
- 1 <= items[i] <= 100
Approaches
- Counter, then halve each tally — time O(n), space O(k)
Related problems
Start free on Cariara · Coding problems · System design studio