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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:10:27+00:00 2026-05-24T01:10:27+00:00

I have a list of Foo with these properties: class Foo ( Date From

  • 0

I have a list of Foo with these properties:

class Foo
(
    Date From
    Date To
    int Importance
)

The From and To dates of these items can overlap. Where two foos overlap, the foo with the highest Importance overrides the other items.

Is there an elegant algorithm to take a list of Foo and resolve any overlaps (by determining which Foo has the highest Importance factor) using the above rules? My attempts so far have been ugly. Ultimately they come down to a series of checks for each possible overlapping conflict, such as a higher priority preceding a lower priority foo, a higher priority foo appearing in the middle of the range of a lower priority foo, and so on. Such a strategy looks unmaintainable and begs for a more elegant approach that I haven’t yet found.

The big issue here is that a higher priority Foo can subdivide a lower priority one, so we can’t simply adjust the From and To points of conflicting Foos.

  • 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-24T01:10:28+00:00Added an answer on May 24, 2026 at 1:10 am

    You can use a priority queue.

    1. Generate all triples (Date, bool, int), where the first argument is a To or From property of one of the Foos and bool indicates whether it’s a To (true) or From (false) and the int one is the priority.
    2. Sort the list of those pairs by Date
    3. Create an empty priority queue of of triples ordered by Importance.
    4. Iterate over the sorted list and for each triple (date, isTo, importance) do:

      a. If it’s a From (isTo=false) then add to the queue

      b. If it’s a To (isTo=true) then remove from the queue

    At any time the max element in the queue (which you can lookup in O(1)) contains the one who wins for that time.

    (If you need the actual Foo object, just make the triple a 4-tuple with a reference to the Foo).

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

Sidebar

Related Questions

Concerning data binding I have these classes: public class Foo : List<Bar> { public
if i have class foo { int a int b } and a List<foo>
i have a class like below public class Foo<T> { public List<T> Items{ get;
A simplified scenario: I have a List<Foo> . Foo has two properties Description (
I have a list of Foo . Foo has properties Bar and Lum .
I have a List<Foo> , and a compare() method taking two Foo objects and
I have a custom class Foo with properties A and B. I want to
I have a List (Foo) and I want to see if it's equal to
I have a List of Foo. Foo has a string property named Bar. I'd
I have a List, it has Foo objects, and each Foo has a start

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.