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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:43:32+00:00 2026-05-26T22:43:32+00:00

I have a sorted list of overlapping intervals, intervals are never contained in each

  • 0

I have a sorted list of overlapping intervals, intervals are never contained in each other, e.g.,

[(7, 11), (9, 14), (12,  17)]

The constraint for the output is to keep every element as close as possible to its
origin (the middle of the interval), preserve the order of the input, and remove all overlap. Only an
approximate solution is necessary. The expected result for the example input would be:

[(5,9), (9, 14), (14, 19)]

I’m only aware of solutions that go about this in some simulation
style: shift each element by some value in a free direction and
iterate until all overlap has been removed.

Is there an existing algorithm to solve this?

  • 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-26T22:43:33+00:00Added an answer on May 26, 2026 at 10:43 pm

    find the overall average:

    in our example:

    (7 + 11 + 9 + 14 + 12 + 17)/6 = 11.667
    

    find the total length:

    (11-7) + (14-9) + (17-12) = 4 + 5 + 5 = 14;
    

    find the new min/max;

    14/2 = 7
    11.667 - 7 = 4.667
    11.667 + 7 = 18.667
    

    you can round ’em

    4.667 ~ 5
    18.667 ~ 19
    

    start from the min, creating the sections by the intervals

    (5, (11-7)+5) = (5,9)
    (9, (14-9)+9) = (9,14)
    (14, (17-12)+14) = (14,19)
    

    NOTE:

    this method will not keep the elements as equal as possible to the originals, but will keep them as close as possible to the original considering their relative values (preserving the center)

    EDIT:

    if you want to keep the averages of all intervals as close as possible to the original, you can implement a mathematical solution.

    our problem’s input is:

    a1=(a1,1, a1,2) , … , an=(an,1,an,2)

    we will define:

    ai1 = a1,2-a1,1 // define the intervals

    b1 = (d, d+ai1)

    bn = (d + sum(ai1..ain-1), d + sum(ai1..ain) )

    bi1 = b1,2-b1,1 // define the intervals

    we need to find a ‘d’ such as:

    s = sum( abs((a1,1+a1,2)/2 – (b1,1+b1,2)/2) )

    min(s) is what we want

    in our example:

    a1 = (7,11), ai1 = 4, Aavg1 = 9

    a2 = (9,14), ai2 = 5, Aavg2 = 11.5

    a3 = (12,7), ai3 = 5, Aavg3 = 14.5

    b1 = (d, d+4) Bavg1 = d+2

    b2 = (d+4, d+9) Bavg2 = d+6.5

    b3 = (d+9, d+14) Bavg3 = d+11.5

    s = abs(9-(d+2)) + abs(11.5-(d+6.5)) + abs(14.5-(d+11.5)) = abs(7-d) + abs(5-d) + abs(3-d)

    now calculcate the derivative to find min/max OR iterate over d to get a result. in our case you will need to iterate from 3 to 7

    that should do the trick

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

Sidebar

Related Questions

I have sorted collection (List) and I need to keep it sorted at all
I have a sorted list of datetimes in text format. The format of each
I have a sorted list at hand. Now i add a new element to
I have a sorted list of disjoint intervals and an interval, e.g. [(1, 5),
I have two lists of objects. Each list is already sorted by a property
I have sorted list of strings that I move between php and java. to
I'm working in c#. I have a sorted List of structures. The structure has
I have a list of instances of the class 'Chromosome'. The list is sorted
I have a list of tuple, the list was sorted based on the first
I have a list of items sorted alphabetically: mylist = [a,b,c,d,e,f,g,h,i,j] I'm able to

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.