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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:49:53+00:00 2026-06-09T07:49:53+00:00

I have a list of ranges. Each range has a from and to value,

  • 0

I have a list of ranges. Each range has a from and to value, meaning the value can be between that range. For eample if range is (1,4)., the values can be 1,2,3 and 4. Now, I need to find the distinct values in a given list of range. Below is the sample code.

class Program
{
    static void Main(string[] args)
    {
        List<Range> values = new List<Range>();
        values.Add(new Range(1, 2));
        values.Add(new Range(1, 3));
        values.Add(new Range(1, 4));
        values.Add(new Range(3, 5));
        values.Add(new Range(7, 10));
        values.Add(new Range(7, 8));

        // Expected Output from the range of values
        //1,2,3,4,5,7,8,9,10
    }
}
class Range
{
    public Range(int _form, int _to)
    {
        from = _from;
        to = _to;
    }
    private int from;

    public int From
    {
        get { return from; }
        set { from = value; }
    }

    private int to;

    public int To
    {
        get { return to; }
        set { to = value; }
    }

}

I can loop through every range and find the distinct values. but if some one can give an effieient approach, it would be helpful.

  • 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-09T07:49:55+00:00Added an answer on June 9, 2026 at 7:49 am
    • For a small number of intervals, the straightforward approach should do the trick.
    • If most intervals fold into each other, you can perform a preliminary step of merging them to reduce the number of tests
    • If the number of disjoint intervals is high, build an Interval Tree. Here is a link to an article with code example in Java.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2-dimensional list of named tuples (let's say that each tuple has
I have an List<int> which contains 1,2,4,7,9 for example. I have a range from
I have a list of DrawObject[] . Each DrawObject has a Rectangle property. Here
I have a list, each item of which has several things in it, including
Let's say I have a list of arbitrary length, L: L = list(range(1000)) What
I have a list iteration in python defined like this: for i in range(5):
I have list of structure. I want to modify a particular data from the
i have list of rows that user select and i want to delete them,
I have a WebForms page that has two DropDownList controls on it that both
I have a list of objects, each with a bool ShouldRun() method on them.

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.