Matching Sock Pairs
colors[i] is the colour code of the i-th sock in a laundry pile. Two socks make a pair only when they have the same colour code, and each sock can belong to at most one pair.
Return the largest number of pairs that can be made from the pile. The empty pile gives 0.
Example 1
colors [1,2,1,2,1,3,2]
returns 2
Colour 1 appears three times (one pair, one left over), colour 2 three times (one pair) and colour 3 once: two pairs.
Example 2
colors [4,4,4,4]
returns 2
Four socks of one colour make two pairs.
Constraints
0 <= len(colors) <= 100-1000 <= colors[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.