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 6882473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:15:27+00:00 2026-05-27T05:15:27+00:00

I am looking for a faster solution to the following problem. I have three

  • 0

I am looking for a faster solution to the following problem.

I have three lists of products available in three different stores. I want to create a unique list containing all products available in the three stores and a unique list of products that appear in more than one store.

class Product{
    public int Id;
    // 
    public Product(int id)
    {
        this.Id = id;
    }
}
List<Product> store1 = new List<Product>();
List<Product> store2 = new List<Product>();
List<Product> store3 = new List<Product>();
List<Product> allUniqueProducts = new List<Product>();
List<Product> moreThanOneStore= new List<Product>();

Fill the lists with some arbitrary values

for(int i=0;i<10000;i++){
    store1.Add(new Product(i));
    store2.Add(new Product(i+2000));
    store3.Add(new Product(i+5000));
}

This is my solution however when the lists are large (in the region of 10,000) this code runs pretty slowly.

processStoreList(store1);
processStoreList(store2);
processStoreList(store3);

void processStoreList( List<Product> storeList ){

    foreach ( Product pd in storeList ){

        if ( !( allUniqueProducts.Count( x => x.Id == pd.Id ) > 0 ))
            allUniqueProducts.Add(pd);

        else if ( !( moreThanOneStore.Count( x => x.Id == pd.Id ) > 0 ))
            moreThanOneStore.Add(pd);
     }
}

Any suggestions?

  • 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-27T05:15:28+00:00Added an answer on May 27, 2026 at 5:15 am

    You should use a Dictionary<int, Product> instead of List<Product>.

    This way, ContainsKey will be O(1) instead of O(n)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a faster way to calculate GC content for DNA strings read
I m looking for a faster implementation or good a approximation of functions provided
Looking into selector performance between $('#ID1, #ID2, #ID3') vs $('1X CLASS'). Which is faster?
I'm looking for a library like Cairo, just far faster. It has to be
Looking for C# class which wraps calls to do the following: read and write
I have an simple question (?) about SQL. I have come across this problem
What I'm looking for is a basic operation (Which I'm sure have a name
I have a project that stores several millions of domain names in database and
I'm looking to increment a value by one and Python does not have the
I'm looking for an efficient algorithm (ideally, C-like pseudocode) to give an approximate solution

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.