GeeksforGeeks » Interview Questions

Compare lists and get top pairs

(2 posts)
  1. stall10n
    Member
    Posted 5 months ago #

    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 6

    Top Pairs
    ========
    1,6 - 3 times
    1,5 - 2 times
    4,5 - 2 times

    How to do this efficiently?

  2. kartik
    Moderator
    Posted 5 months ago #

    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.

RSS feed for this topic