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

  • Home
  • SEARCH
  • 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 9147259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:56:41+00:00 2026-06-17T10:56:41+00:00

I have a single array with these entries: {1, 1, 2, 2, 3,3,3, 4}

  • 0

I have a single array with these entries:

{1, 1, 2, 2, 3,3,3, 4}

and i want to transform them to ( 3 lists in this case ):

{1,2,3,4}
{1,2,3}
{3}

Is there any way to do this with LINQ or SQL? I guess there’s a mathematical term for this operation, which I don’t know unfortunately…

Or do I have to do it with loops?

=======

EDIT: I can’t really describe the logic, so here are more examples.. It more or less loops multiple times over the array and takes every number once ( but every number only once per round ) until there are no numbers left

{1, 1, 2, 2, 3,3,3, 4, 5}
would be
{1,2,3,4,5}
{1,2,3}
{3}

or

{1, 1, 2, 2,2, 3,3,3, 4, 5}
would be
{1,2,3,4,5}
{1,2,3}
{2,3}

  • 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-17T10:56:42+00:00Added an answer on June 17, 2026 at 10:56 am
    private IEnumerable<List<int>> FooSplit(IEnumerable<int> items)
    {
        List<int> source = new List<int>(items);
        while (source.Any())
        {
            var result = source.Distinct().ToList();
            yield return result;
            result.ForEach(item => source.Remove(item));
        }
    }
    

    Usage:

    int[] items =  { 1, 1, 2, 2, 3, 3, 3, 4 };
    
    foreach(var subList in FooSplit(items))
    {
        // here you have your three sublists
    }
    

    Here is another solution, which is less readable but it will have better performance:

    private IEnumerable<IEnumerable<int>> FooSplit(IEnumerable<int> items)
    {
        var groups = items.GroupBy(i => i).Select(g => g.ToList()).ToList();    
    
        while (groups.Count > 0)
        {
           yield return groups.Select( g => 
                 { var i = g[0]; g.RemoveAt(g.Count - 1); return i; });
           groups.RemoveAll(g => g.Count == 0);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays, I want to merge these two arrays into single array.
Say I have an array of arbitrary size holding single characters. I want to
I have no idea if this is possible but is there a way in
I want to store an array of latitudes/longitudes. I have these inputs on my
I have three array..say array1,array2,array3. All these arrays contains dictionary.Now, I want to copy
I have three arrays and I have copied all these arrays into a single
How can I store arrays in single array? e.g. I have four different arrays,
I need to display array of images in a single view which have various
iam having an array of items like [item1,itmem2,item3]; i have to insert these items
I have this weird situation. I have these two classes: Public Class Entry End

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.