Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [interval]

For code using intervals to measure “distance” between values, possibly as input, output, or in method calls.

-3
votes
0answers
8 views

How to store a range of generated numbers using IntStream to a text file [on hold]

I wrote a program to generate a range of numbers using IntStream (java 8) but can seems to figure out a way to store the generated numbers into a text file. I know how to store Strings to a file but ...
4
votes
3answers
272 views

Collect subsequences of consecutive integers

I've written a function to split a list into several lists with consecutive integers, e.g.: extract_subsequences([1,2,3,7,8,9]) ...
0
votes
0answers
23 views

Laravel working with dynamic start and end dates to grab some data

So, to start off, the below code does work, but it feels like a newbie solution to me, and if I ever need to come back to this code, I will have no idea what I was thinking. I have a table called <...
4
votes
2answers
48 views

Python Float point range() operator implementation

I recently wrote a full implementation of a range() operator with floating point values in Python, and I'm not sure if I've followed the standard pythonic patterns. ...
6
votes
3answers
1k views

Checking if two time intervals overlap

I have two time intervals i1 and i2, each defined by two values, begin and ...
4
votes
1answer
167 views

Counting integers that are within intervals

I am looking for a more efficient way than bruteforcing my way through in the following problem in python 3. Problem statement: Input: An array of n integers, scores, where each score is denoted by ...
6
votes
2answers
664 views

Find the intervals which have a non-empty intersection with a given interval

The problem is the following: I have a list intervals which consists of tuples of the form (start, end) [with ...
3
votes
3answers
116 views

Add dash between more than two consecutive numbers and comma between other numbers in array

I have an ordered array of integer values: 10, 11, 12, 13, 15, 16, 19 and I need to write a dash between first and last consecutive values when there are more than two consecutive values (10-13). ...
5
votes
1answer
102 views

Calculate the intersections of opening hours

I have a solution but it feels bloated and unclean. How can I clean it up? The second for loop especially does not feel right. I'm trying to calculate the opening ...
2
votes
0answers
83 views

PostgreSQL: maintaining non-overlapping temporal ranges

I have to store some temporal meta data used primarily in bulk processing of a time-series (sensor measurements). Each value of this meta data is valid for a potentially half-open range of time. ...
2
votes
1answer
260 views

Merge a new interval into given array of intervals

This is Merge Intervals problem from www.interviewbit.com Problem : Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that ...
4
votes
3answers
474 views

Hackerrank challenge - Apple and Orange

The problem I am trying to solve is this. Apples fall at various offsets relative to an apple tree at position a, and oranges fall at various given offsets relative to an orange tree at position b. ...
3
votes
3answers
305 views

Merge intervals

Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. GitHub ...
1
vote
2answers
175 views

Intersection of the interval set

Recently I had an interview where it was asked: Given a list of people with their birth and end years find the year with the most number of people alive. I implemented in Java and was trying to find ...
8
votes
2answers
746 views

Traffic speed limit check for intervals

Given 2 lists of tuples limits and speeds, both have the format of [(speed1, time1), (speed2, time2)]. My goal is to write a ...
2
votes
1answer
220 views

Return the optimal time slot

Implement a function meetingPlanner that given the availability, slotsA and slotsB, of two people and a meeting duration dur, returns the earliest time slot that works for both of them and is of ...
1
vote
0answers
35 views

Box partitioning with arrays of boost::intervals

I need to write a function that takes a box in space, represented as an std::vector of boost::intervals, and split it into several smaller boxes. First, for convenience, I made some definitions <...
1
vote
1answer
129 views

Finding the longest overlapping period

I have a list of records containing Id, DateFrom, DateTo. For the sake of this question we can use this one: ...
17
votes
5answers
2k views

Flipping coins performance

This is the Flipping coins problem on CodeChef: There are \$N\$ coins kept on the table, numbered from \$0\$ to \$N - 1\$. Initially, each coin is kept tails up. You have to perform two types of ...
1
vote
1answer
62 views

Searching and sorting ranges in excel with toggle buttons

I have a spreadsheet containing ±100 named ranges (5 rows, 15 colums) which are sorted based on time. My plan was to make toggle buttons to hide or unhide named ranges when they contain a certain ...
5
votes
1answer
306 views

Merge Intervals from leetcode [closed]

Given a collection of intervals, merge all overlapping intervals. input: [1,3],[2,6],[8,10],[15,18], output: [1,6],[8,10],[15,18]. The logic is very simple: just merge all the intervals ...
4
votes
1answer
440 views

Check if two date ranges overlap by X minutes

I have a list of volunteer shifts. The shifts are time ranges- for example, 9AM-2PM and 12PM-5PM. I need to check by how many minutes multiple selected shifts overlap, and then throw an error if the ...
3
votes
2answers
2k views
3
votes
1answer
134 views

Group time intervals together

A while back, I supplied an answer on SO for grouping time intervals together. Say you have an array like this: ...
4
votes
2answers
101 views

Pattern finding function for years between 1998 and 2017 with several test cases

Pattern matching for years, I need to be able to return all years from a string. When there is a dash "-" I need to return all numbers between. For example, '2004-2006' should return an array of ...
0
votes
1answer
61 views

Class for managing blocks of working hours

I have written the following class: NOTE: There is a bug in the third party component that means that if a DHXBlockTime is there for a day of the week and a ...
2
votes
1answer
42 views

Query to use the longer of two date-time ranges

I have a complex date-and-time-matching query in the middle of another huge query. I'm matching two tables, the second one is LEFT JOINed to the first. If the time ...
1
vote
0answers
65 views

Time Schedule Intersection version 2

Time schedule intersection in my original question I gave an answer which has \$O(n^2)\$ complexity. Here is the new version of the same problem. I'm trying to get to O(N+K). please review the code ...
0
votes
1answer
95 views

Query an array at intervals and getting the highest number of values

I feel like I am doing a lot of unnecessary operations and some places I feel like I am being redundant in some places. I am focused on performance and optimization. I am trying to find the five ...
3
votes
1answer
375 views

C++ header only library for interval arithmetic (only supports addition)

I'm trying to make a simple header only C++ library for interval arithmetic as a programming exercise. There are some subtle aspects of interval arithmetic (like floating point rounding mode) that I ...
5
votes
1answer
485 views

Airport scheduler

This is the problem: Airport Pretend we are operating a small airport with a single runway. We need to develop a data structure to help scheduling airplanes to take off and land from this ...
1
vote
0answers
278 views

Time schedule intersection

I had a job interview one of the questions was the following Given an api - you submit a name of a person and it gives back a sorted list of all the free time slots this person has. the list might be ...
4
votes
1answer
64 views

Excel VBA object with validated bounds for an interval

I'm working through a problem I have with Excel VBA. I have two object classes. Class clsLoadStep stores three copies of class clsLoad objects. Class clsLoad simply stores a value and a string stating ...
8
votes
1answer
4k views

An interval-map data structure

This data structure maps values from intervals of some type Key which satisfies LessThanComparable<Key> to values of some ...
3
votes
1answer
421 views

C# greedy algorithm to pick activities that do not clash with each other (corrected)

My task is the greedy algorithm: The activity selection problem is characteristic to this class of problems, where the goal is to pick the maximum number of activities that do not clash with each ...
4
votes
1answer
2k views

Implementing views on a std::vector

Goal: Wrap a vector. The wrapper can create view on part of the vector. Support const_view and view. view allows modification of elements while const_view does not. The views are ranges (has begin() ...
1
vote
2answers
748 views

Checking whether number is in given range

Introduction I want to check whether number is in given range. Function takes: long number that should be checked 2 longs threshold values byte range mode Range mode is represented as number of ...
8
votes
3answers
1k views

Leetcode 56: Merge Intervals

Problem statement Given a collection of intervals, merge all overlapping intervals. For example: Given \$[1,3],[2,6],[8,10],[15,18]\$, return \$[1,6],[8,10],[15,18]\$. My ...
4
votes
4answers
1k views

Points and segments solution

Task: Given a set of points on a line and a set of segments on a line. The goal is to compute, for each point, the number of segments that contain this point. Input Format The first ...
3
votes
1answer
212 views

Start and end times of recurring events

I'm working on a function that returns a specific set of times for a given timezone and a given frequency; day, week, month. For any given timezone and a frequency the function will return the ...
2
votes
1answer
64 views

Segment tree challenge

Here is my implementation of a segment tree with a sample driver file (I didn't make an update function because I didn't need it for what I was doing). I'm a huge fan of geeksforgeeks, but I do not ...
5
votes
1answer
1k views

Calculate attendance compliance based on attendance record

This is part of a larger working system which I'm now trying to clean up. In the interests of making the system more test-able I'm splitting up the functions which can be split, but this 100-line ...
4
votes
1answer
492 views

Data Stream as Disjoint intervals

I was asked the following question: Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals. For example, ...
5
votes
1answer
116 views

Merging trips to the same location with overlapping dates

I have a SQLite database that only contains the holidays for 1 user. I have a new Trip object (newTrip) that has a ...
4
votes
4answers
164 views

Subdividing intervals that contain the largest error values

I'm trying to accomplish the following: Start out with 1 interval on the real line. This interval is processed in some function and out comes an array of errors (size < 10 usually). The maximum ...
3
votes
1answer
514 views

Finding the total time elapsed in the union of time intervals

Given a set of time intervals, I have to find the total time elapsed in the union of the intervals. Test Cases: ...
1
vote
2answers
2k views

Intersect two ranges in Swift

Can you think of a reason the following extension should not be used in production, or a better way of implementing it: ...
1
vote
0answers
97 views

Insert an interval into a list of sorted disjoint intervals

The code works on my one test case. What do you think about it? Can it be simplified? ...
1
vote
0answers
29 views

Getting all timeDuration from a day which are not in a list of timeDuration in Scala

I have a list of timestamp tuples of the form List((startTime,endTime)), which are basically denoting periods of time throughout the day. For example: ...
2
votes
2answers
711 views

Redux isomorphic fetch in interval

I'm not really sure if the following solution is the best fit, and I would like to know best practices when manipulating state and/or Ajax isomorphic fetch requests, in this case, in intervals. ...