Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1027069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:10:59+00:00 2026-05-16T12:10:59+00:00

Simple situation. I have a list of lists, almost table like, and I am

  • 0

Simple situation. I have a list of lists, almost table like, and I am trying to find out if any of the lists are duplicated.

Example:

List<List<int>> list = new List<List<int>>(){
  new List<int>() {0 ,1 ,2, 3, 4, 5, 6 },
  new List<int>() {0 ,1 ,2, 3, 4, 5, 6 },
  new List<int>() {0 ,1 ,4, 2, 4, 5, 6 },
  new List<int>() {0 ,3 ,2, 5, 1, 6, 4 }
};

I would like to know that there are 4 total items, 2 of which are duplicates. I was thinking about doing something like a SQL checksum but I didn’t know if there was a better/easier way.

I care about performance, and I care about ordering.

Additional Information That May Help

  • Things inserted into this list will never be removed
  • Not bound to any specific collection.
  • Dont care about function signature
  • They type is not restricted to int
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:11:00+00:00Added an answer on May 16, 2026 at 12:11 pm

    Let’s try to get best performace. if n is number of lists and m is length of lists then we can get O(nm + nlogn + n) plus some probability of hash codes to be equal for different lists.

    Major steps:

    1. Calculate hash codes*
    2. Sort them
    3. Go over list to find dupes

    * this is important step. for simlicity you can calc hash as = … ^ (list[i] << i) ^ (list[i + 1] << (i + 1))

    Edit for those people that think that PLINQ can boost the thing, but not good algorythm. PLINQ can also be added here, because all the steps are easily parallelizable.

    My code:

    static public void Main()
    {
        List<List<int>> list = new List<List<int>>(){
          new List<int>() {0 ,1 ,2, 3, 4, 5, 6 },
          new List<int>() {0 ,1 ,2, 3, 4, 5, 6 },
          new List<int>() {0 ,1 ,4, 2, 4, 5, 6 },
          new List<int>() {0 ,3 ,2, 5, 1, 6, 4 }
        };
        var hashList = list.Select((l, ind) =>
        {
            uint hash = 0;
            for (int i = 0; i < l.Count; i++)
            {
                uint el = (uint)l[i];
                hash ^= (el << i) | (el >> (32 - i));
            }
            return new {hash, ind};
        }).OrderBy(l => l.hash).ToList();
        //hashList.Sort();
        uint prevHash = hashList[0].hash;
        int firstInd = 0;            
        for (int i = 1; i <= hashList.Count; i++)
        {
            if (i == hashList.Count || hashList[i].hash != prevHash)
            {
                for (int n = firstInd; n < i; n++)
                    for (int m = n + 1; m < i; m++)
                    {
                        List<int> x = list[hashList[n].ind];
                        List<int> y = list[hashList[m].ind];
                        if (x.Count == y.Count && x.SequenceEqual(y))
                            Console.WriteLine("Dupes: {0} and {1}", hashList[n].ind, hashList[m].ind);
                    }                    
            }
            if (i == hashList.Count)
                break;
            if (hashList[i].hash != prevHash)
            {
                firstInd = i;
                prevHash = hashList[i].hash;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation in C# where I have a list of simple types.
I have a situation that is pretty simple, and I'd like to know the
I have a simple situation here. lets face html code first => <form name=geoKey
My situation is simple. I have this in my program: File folder = new
I have a simple parent-child situation where the parent can have multiple children. The
The situation is very simple, I have two panel. In the event of OnMouseOver
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I have a situation where I could really benefit from having system like memcached,
The situation is simple. I have a datagrid that gets its data from a
I have very simple situation and really don't have a clue why this isn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.