GeeksforGeeks » Interview Questions
Compare lists and get top pairs
(2 posts)-
I have many lists which each one have 6 elements. I want to compare them and get top pairs.
List 1 => 1 4 5 6 5 7
List 2 => 2 3 8 6 1 9
List 3 => 4 7 1 3 5 6Top Pairs
========
1,6 - 3 times
1,5 - 2 times
4,5 - 2 timesHow to do this efficiently?
-
1) Create an empty hash table where a pair is used as key and number of occurrences for a pair as value. 2) Consider all sets one by one a) Generate all possible pairs in the current set. For each pair, increase the occurrence count for the pair in hash table. 3) Sort the hash table according to count and print entries in descending order
Reply
You must log in to post.