Solution HackerRank:Sock Merchant

Tram Ho

1. Topic

Given an array of integer n elements, count how many pairs of integers in the array (each integer can only be matched once).

The range of values ​​for n: from 2 to 10 ^ 6.

Sample Input:

Sample Output:

Describe titles in pictures:

2. Directions.

With connecting the pairs of numbers together which numbers have joined and not considered anymore. Thus we must have an array to store between states.

Browse each element in the array with the remaining elements. If conditions are equal and their state has not been paired, proceed with pairing. Continue with the next number.

3.Code.

Share the news now

Source : Viblo