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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:43:06+00:00 2026-06-09T10:43:06+00:00

I’m going to be as clear as I can. I have an event that

  • 0

I’m going to be as clear as I can.

I have an event that have two times, start and end. (Times are in 24h format)
For example, this event starts at 8, and finishes at 12.

With this event, I have a list of person with their work schedule.
Here’s an example :

  • Person 1 : From 8:00 to 10:00
  • Person 2 : From 10:00 to 12:00
  • Person 3 : From 6:00 to 15:00
  • Person 4 : From 8:00 to 9:00
  • Person 5 : From 9:30 to 12:00

Now, I need to know how many people, at minimum, I have through the whole event.

In my case, it will be 2, because :

  • Person 1 & Person 2 complement each other
  • Person 3 will always be present
  • There is a gasp between person 4 & 5, between 9:00 and 9:30, so during this time, no one between Person 4 & 5 will be present.

If I explain this with times :

  • From 8:00 to 9:00 : Person 1, 3, 4
  • From 9:00 to 9:30 : Person 1, 3
  • From 9:30 to 10:00 : Person 1, 3, 5
  • From 10:00 to 12:00 : Person 2, 3, 5

Most of the time, the event will have 3 person, but the lowest if 2.

How can I get this number using an algorithm, I can’t make my mind with this.

I thought about converting the time in minutes (I won’t go under the minute), set the range at the event times (from 8*60 to 12*60), and add each person presence as a new range, and then count for each minutes, how many slice there is (1 slice = 1 person). But I feel this isn’t efficient, because I will have to count the slices for 4*60 minutes :/ (from 8 -> 12).

How would you do ?

  • 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-09T10:43:07+00:00Added an answer on June 9, 2026 at 10:43 am

    Take the start and end times for person number i, and name them s_i and e_i.

    Put all of these in a list, times. Then do the following:

    # start_time contains the start time of the event
    # end_time contains the start time of the event
    sort(times) # When doing this sort, make sure that if a s_i
                # is at the same time as a e_j, put the s_i first.
    
    current_number = number of people who're there at start_time
    remove all times that match start_time from times
    
    minimum_number = current_number
    
    for time in times:
        if time is an s_i: current_number += 1
    
        if time is an e_i:
            current_number -= 1
            if current_number < minimum_number and time < end_time:
                minimum_number = current_number
    

    The running time for this is found as follows:

    Let n be the number of people.

    We spend O(n lg n) time doing the sorting, as we only have 2n times to sort.

    We then spend O(n) time iterating through the times, doing constant work.

    Overall, O(n lg n). Note that this running time is completely independent of how large an interval of time it spans over, and is only dependent on how many people you’re dealing with.

    This is a form of sweep line algorithm. We sweep through the times, only stopping at the points of interest (the s_i and e_is.)

    Note, the reason we sort the s_is before e_js in case of a tie, is as follows:

    If we don’t, then imagine we have two people: Bob is here from 8-10, Alice is here from 10-12. We might then, if we don’t do careful sorting, get the following list of times:

    times = [(s_Bob, 8), (e_Bob, 10), (s_Alice, 10), (e_Alice, 12)]
    

    If we sort it like this, then it looks like there are no people left after Bob leaves at 10. However, Alice is there, since she arrives at the same time. Thus, to prevent this, we sort it such that starting times are before ending times, in case of a tie:

    times = [(s_Bob, 8), (s_Alice, 10), (e_Bob, 10), (e_Alice, 12)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.