Question bank › Greedy
Dsa Greedy Medium

Pairing Socks

You have an array of integers representing different colors of socks. Each integer corresponds to a unique color. Your goal is to find the number of pairs of socks you can make, where a pair consists of two socks of the same color. Write a function that takes in the list of integers and returns the total number of pairs that can be formed. Input: The first line contains an integer `n` (1 ≤ n ≤ 100), the number of socks. The second line contains `n` integers representing the colors of the socks (0 ≤ socks[i] ≤ 100). Output: Return the total number of pairs of socks. Example: Input: 9 10 20 20 10 10 30 50 10 20 Output: 3 In this example, there are three pairs: (10, 10), (20, 20), and (10, 10).

Key concepts

greedyhashingarrays

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.