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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:38:29+00:00 2026-05-30T22:38:29+00:00

I have an array of time periods on a given day, where some overlap,

  • 0

I have an array of time periods on a given day, where some overlap, like so (start, end):

(10.00, 10.15) (11.00, 11.30) (11.30, 11.45) (11.45, 12.00) 
(11.45, 12.15) (12.15, 12.45) (13.20, 13.30) (14.15, 14.35) (14.35, 14.40)

I want to find the largest sets of consecutive time periods. In the above example there are 3 sets of consecutive times (shown below) but as the first set is a smaller ‘alternative’ to the second it should be ignored, so we are left with 2 and 3.

  1. 11.00 – 11.30, 11.30 – 11.45, 11.45 – 12.00
  2. 11.00 – 11.30, 11.30 – 11.45, 11.45 – 12.15, 12.15 – 12.45
  3. 14.15 – 14.35, 14.35 – 14.40

One thing I must add: I would like to be able to specify a ‘tolerance’ that defines what consecutive means. In the above example consecutive means end time of first time period == start time of next time period, but it would be great to define consecutive as time periods that are ‘5 minutes apart’, say.

Any ideas on how to do this in php or pseudocode would be greatly appreciated!

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

    This feels like a Dynamic Programming kind of problem. I guess it can be solved as a graph problem, too.

    If you turn your data into a graph: each period is a vertex, two vertices are connected if they are consecutive (use whatever tolerance level you want for this). All edges have the same weight. Now you need to find the longest path on that graph.

    The longest path problem is an NP-complete, which is a bummer. However, with graphs without cycles, it is possible to solve this in polynomial time. Cool. Your graph is a-cyclic I hope (you don’t round around entire days, right?). So, just put a weight of -1 on each edge, and find the shortest graph. The last link I supplied also has a dynamic programming approach for this.

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

Sidebar

Related Questions

I have Array of time string like 10:10:12,12:10:34,05:23:11 this. I want to calculate less(min)
I have an array containing specific times and I want when the current time
Currently I have a function which can take the start time and end time
I have an array that is structured like this: [33] => Array ( [time]
When I have array of ids, like ids = [2,3,5] and I perform Comment.find(ids)
I have a numpy array of ints representing time periods, which I'm currently plotting
I have a multi-dimensional array like so. [0] => Array ( [time] => 1312206805
I have an array with subjects and every subject has connected time. I want
I have an array like this: [234, 235 , 343, 445] I want to
For an instance you have an array: $unsorted = array( 'desert' => array( 'time'

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.