Find pairs function


#1

someone has a guest how can I find the numbers of pairs in an array ?


#2

Assume an array A = {1,6,7,1,8,7,9}

Solution A: (Will work in C) - Brute Force
You could either sort the array (via let’s say the bubblesort or any other algorithm) and then check A[i], A[i+1] to see if matched. Then just increase some counter of yours by one.

Solution B (Need “higher level languages”):
Use a hashmap to hash a tuple <number, times_found_in_array>