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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:57:52+00:00 2026-06-04T09:57:52+00:00

I have a big number of SortedSet<Long> structures: 1, 2, 5, 8, 10, 35,

  • 0

I have a big number of SortedSet<Long> structures:

1, 2, 5, 8, 10, 35, 77, ...
5, 9, 35, 50, 132, ...
2, 4, 8, 15, 17, 23, ...
... hundreds of thousands of such rows...

I need to find a number that goes after, say, 50. In this example (if there are just three sets) it is 77. The number of sets is huge – hundreds of thousands. What algorithm would you suggest?

  • 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-04T09:57:53+00:00Added an answer on June 4, 2026 at 9:57 am

    If I understand correctly here is my idea:

    Collection<SortedSet<Long>> sets = //...
    
    long minAfter50 = Long.MAX_VALUE;
    for (SortedSet<Long> set : sets) {
        final Long first = set.tailSet(51L).first();
        minAfter50 = Math.min(minAfter50, first);
    }
    

    Here is the idea:

    • iterate over all input sets
    • crop all values less then or equal 50
    • take the first argument of the cropped set (guaranteed to be greater than 50)
    • calcualte the smallest value out of those collected in previous step

    UPDATE (based on @beerbajay comment): if SortedSet is actually a TreeSet, the following code might perform better. Also I am making sure that there is any value greater than 50 in each and every set:

    long minAfter50 = Long.MAX_VALUE;
    for (TreeSet<Long> set : sets) {
        final Long higher = set.higher(50L);
        if (higher != null && higher < minAfter50) {
            minAfter50 = higher;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather big number of source files that I need parse and
I have big string in that I need to check if number is present
If have a big 'xsl:choose' chunk in which I need to set a number
I have a big, complex MATLAB program. Somewhere within that, the number 0 is
I need to find a method to read a big number of small files
I have an application that will handle a big number of users. The users
I have the following use case: I need to process a big number of
I have big number, time (micro seconds) stored in two 32bit variables. I need
I have a collection of a big number of objects that are defined by
I have the need to find the next available number in a set: select

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.