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

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…