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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:22:21+00:00 2026-06-14T01:22:21+00:00

Possible Duplicate: Combination of List<List<int>> I have multiple Lists, could be 2 or 3

  • 0

Possible Duplicate:
Combination of List<List<int>>

I have multiple Lists, could be 2 or 3 up to 10 lists, with multiple
values in them. Now what I need to do is to get a combination of all
of them.

For example, if I have 3 lists with the following values:

  • List 1: 3, 5, 7
  • List 2: 3, 5, 6
  • List 3: 2, 9

I would get these combinations

  • 3,3,2
  • 3,3,9
  • 3,5,2
    Etc..

Now the problem is I cannot do this easily because I do not know how many lists I have, therefore determine how many loops I need.

  • 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-06-14T01:22:23+00:00Added an answer on June 14, 2026 at 1:22 am

    You could probably make that a lot easier, but this is what I had in mind just now:

    List<List<int>> lists = new List<List<int>>();
    lists.Add(new List<int>(new int[] { 3, 5, 7 }));
    lists.Add(new List<int>(new int[] { 3, 5, 6 }));
    lists.Add(new List<int>(new int[] { 2, 9 }));
    
    int listCount = lists.Count;
    List<int> indexes = new List<int>();
    for (int i = 0; i < listCount; i++)
        indexes.Add(0);
    
    while (true)
    {
        // construct values
        int[] values = new int[listCount];
        for (int i = 0; i < listCount; i++)
            values[i] = lists[i][indexes[i]];
    
        Console.WriteLine(string.Join(" ", values));
    
        // increment indexes
        int incrementIndex = listCount - 1;
        while (incrementIndex >= 0 && ++indexes[incrementIndex] >= lists[incrementIndex].Count)
        {
            indexes[incrementIndex] = 0;
            incrementIndex--;
        }
    
        // break condition
        if (incrementIndex < 0)
            break;
    }
    

    If I’m not completely wrong, this should be O(Nm) with m being the number of lists and N the number of permutations (product of the lengths of all m lists).

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

Sidebar

Related Questions

Possible Duplicate: Get all possible word combinations I want to get a power list
Possible Duplicate: Generate list of all possible permutations of a string I need to
Possible Duplicate: Python code to pick out all possible combinations from a list? I
Possible Duplicate: <: cannot begin a template argument list Did you know that int
Possible Duplicate: const int = int const? What is the difference between these combination
How can I get the Cartesian product (every possible combination of values) from a
Possible Duplicate: Unique Constraint, excluding NULL values Lets say i have a table with
Possible Duplicate: Get the cartesian product of a series of lists in Python I'm
Possible Duplicate: PHP take all combinations I'm thinking of making something in PHP that
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want

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.