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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:36:23+00:00 2026-05-12T22:36:23+00:00

here is my problem. I have a list of data, sorted by dateStart :

  • 0

here is my problem. I have a list of data, sorted by dateStart :


index    dateStart           dateEnd            value
[0]      2009-11-01 04:20  2009-11-01 05:40   5
[1]      2009-11-01 06:30  2009-11-01 08:42   10
[2]      2009-11-01 07:43  2009-11-01 16:12   0
[3]      2009-11-01 10:43  2009-11-01 14:34   -12
[4]      2009-11-01 12:34  2009-11-01 12:42   3

The final output that I want would be a subset from that list, where dateStart and dateEnd from 2 different items would never clash.

In the current example, I would start at [0] and keep it.
For [1], since its dateStart > [0].dateEnd, I would also keep it.
For [2], since its dateStart <= [1].dateEnd, I would discard it.
For [3], since its dateStart > [2].dateEnd, I would keep it.
For [4], since its dateStart <= [3].dateEnd, I would discard it.

and so on.

I would like to use LINQ (lamda preferred) for that, if possible.
Otherwise, I guess a standard for loop would do the trick.

Another interesting way of getting my final output would be to keep all the data, but add a flag to each item (bValid), that would indicate if the data is to be taken or not.

Thanks!
p.s. sorry for Formatting, I tried my best (first post here)

  • 1 1 Answer
  • 2 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-12T22:36:23+00:00Added an answer on May 12, 2026 at 10:36 pm

    I think you have an error in one case:

    For [3], since its dateStart > [2].dateEnd, I would keep it. 
    
    10:43 > 16:12  --> False
    

    I think this covers what your asking. Though I don’t know if you want to check the EndDate of previous discarded items or the last item that was accepted.

            IEnumerable<MyObj> res = l.Where((o,i) => { 
                if (i == 0)
                    return true;
                else 
                    return o.DateStart > l.ElementAt(i-1).DateEnd;
            });
    

    This only outputs:

    0 01-11-2009 4:20:00 01-11-2009 5:40:00 5
    1 01-11-2009 6:30:00 01-11-2009 8:42:00 10
    

    because of the early high EndDate 16:12.

    (update)

    Ok, I saw your comments. This totally changes things. Try this:

        static IEnumerable<MyObj> MyFilter(IEnumerable<MyObj> input)
        {
            MyObj aux = input.First();
            yield return aux;
            foreach (var o in input.Skip(1))
            {
                if (o.DateStart > aux.DateEnd)
                {
                    aux = o;
                    yield return aux;
                }
            }
        }
    

    It outputs:

    0 01-11-2009 4:20:00 01-11-2009 5:40:00 5
    1 01-11-2009 6:30:00 01-11-2009 8:42:00 10
    3 01-11-2009 10:43:00 01-11-2009 14:34:00 -12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 285k
  • Answers 285k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I couldn't find a document outlining a conclusive list, but… May 13, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer iter() is an iterator over a sequence. [x] * n… May 13, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer there, a coworker of mine pointed out the problem. It… May 13, 2026 at 4:49 pm

Related Questions

Ok..so I'm a nOOb with jquery. I have a dynamically created list of items
I have written a function that gets a given number of random records from
I have a Silverlight Autocompletebox to show a list of staff members, and it
I have read a ton about this problem, but I cannot figure it out.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.