Questions tagged [interval]

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

Filter by
Sorted by
Tagged with
2 votes
2 answers
60 views

Given a sorted list of integers, find the highest count of elements between an indeterminate but fixed size range

I'm trying to optimize a function that takes a sorted list of integers and tells me what is the maximum number of elements in the list between any definite size range. To be clear, the range itself ...
Tyler Schuster's user avatar
4 votes
1 answer
79 views

Generate varied values of some parameters over a neighboring interval

I was recently tasked with creating a function that could generate a "varied" version of some collection of parameters. As in, it should take in a list of parameters, and then vary the value ...
horriblehaskell's user avatar
1 vote
0 answers
43 views

Testing whether one interval overlaps other intervals

I recently started to learn functional programming and wan't to know If I'm doing things right. I use @effect-ts/core lib as well as ...
Roman Mahotskyi's user avatar
4 votes
6 answers
445 views

Finding missing numbers in ranges

I have a list of (potentially overlapping) ranges, e.g [(3, 9), (8, 10), (1, 18), (1, 1000000)]. I need to process them in order and for each range calculate how ...
Eugene Yarmash's user avatar
6 votes
3 answers
1k views

Count the numbers in a range in which the sum of the odds digits have the same parity of the evens one

As already written in the title I want to count the numbers in the range (x+1, y) where x and y are integers, in which the sum of the digits in odd places have the same parity of the ones in even ...
DarkSkull's user avatar
  • 163
2 votes
1 answer
36 views

Find coherent datetime ranges in postgresql

My Data consists of rows containing a Length/Duration in Minutes, a Begin & EndTime. The precision is 1min (or larger). the table looks something like that: ...
Fritz's user avatar
  • 121
-1 votes
1 answer
300 views

Hackerrank Gridland Metro - using Interval Cover Solution [closed]

Hi there I was hoping to get a better grasp of greddy algorithms while trying to solve this problem: Hackerrank: Gridland Metro and I was trying to apply an algorithm where each grid could be ...
Elliott de Launay's user avatar
2 votes
1 answer
378 views

Implement a range behaviour in Python using iterators

I've been assigned the following Python homework: Implement myrange that acts like range using iterators. Define a function ...
bobinthebox's user avatar
3 votes
1 answer
39 views

Calculating difference between cached period and requested

There is a remote resource containing datasets arranged by time, data is static and doesnt change. Whenever we are going to fetch anything from there we will be saving it in our cache. User might ...
RB_'s user avatar
  • 133
3 votes
2 answers
67 views

C++ PixelComponent struct

Hey I wrote a struct in C++ trying to represent a Pixel Component of a color Here it is ...
Hrant Nurijanyan's user avatar
1 vote
1 answer
2k views

The most minimal way to retrieve live data using setInterval

I am writing a script that is supposed to retrieve some data from a MYSQL database but I need to make it happen live and after lots of research I learned that this thing can be done using something ...
Nyx's user avatar
  • 113
2 votes
1 answer
106 views

template iterable numeric range class with multiple min/max inclusion modes

Problem my code solves: Lack of lightweight numeric range classes which can tell if arbitrary values lie inside them, supporting more than just simple exclusive max modes and integers, and that ...
Krupip's user avatar
  • 621
2 votes
0 answers
52 views

Using python to estimate the range of unstructured data

I have unstructured input-output data, f=f(x). I want to estimate the range of f as a function of x, given limited sampled. So, I tried to discretize the data use small bins in x to estimate the ...
kilojoules's user avatar
4 votes
2 answers
140 views

Simple timestamping filter in C

I wrote a simple timestamping filter that prepends each line with the UNIX timestamp in nanosecond precision as returned by clock_gettime, as well as the difference to the previous timestamp. ...
Thure Dührsen's user avatar
16 votes
1 answer
2k views

Pure python range implementation

I implemented class Range as an equivalent to Python built-in range for practicing purposes. No features were added. Hope it ...
sanyassh's user avatar
  • 315
6 votes
2 answers
547 views

Modeling and computing intersection between continuous intervals

I created the class ContinuousDimensionInterval, to model an interval of a continuous dimension interval, presented below. ...
Trauer's user avatar
  • 801
3 votes
1 answer
62 views

List of dates with special formatting

I have a code that calls many times a function returning a list of the dates between two dates formatted as ('0001-01-01 00:01:00'),('0001-01-02 00:01:00'), ... The current solution is: ...
shamalaia's user avatar
  • 255
3 votes
1 answer
233 views

Continuous Range class

I was surprised to find that there doesn't seem to be a good "continuous range from start to end" data structure in python. I ...
Green Cloak Guy's user avatar
4 votes
1 answer
2k views

Difference between dates in Months and Days [closed]

I've written a function that returns how many Months and Days are between two dates. I want to respect calendar month boundaries, but I'm ignoring time as it's not relevant for my needs. I've got the ...
Nick Albrecht's user avatar
3 votes
1 answer
68 views

Range validator for multiple types

I have an existing overloaded set of functions that I cannot change and need to be tested: ...
ordonezalex's user avatar
5 votes
1 answer
164 views

Coalescing ranges that have the same label

I am working with some data that requires keeping track of different types of ranges. There are three key attributes to keep track of: type (str): the "type" of the range start (int): the value at ...
SumNeuron's user avatar
  • 271
4 votes
1 answer
52 views

Time interval class that enhances constructor argument handling of its parent class

I am making a subclass of a well-established python class: pendulum.Period, which overrides both __new__ and ...
Brandon Kuczenski's user avatar
2 votes
1 answer
156 views

Performance issue with empty lists

Here's my updated version of the problem I posted at Calculating time windows for entities, adding in suggested changes as well as a change I did so that the Reflection is 'cached' in a ...
Mark Cilia Vincenti's user avatar
6 votes
3 answers
362 views

Calculating time windows for entities

I have made some code that operates on multiple entities and creates 'time windows' for them. Basically, the entities will contain states, usually in boolean or int. They will be timestamped and in ...
Mark Cilia Vincenti's user avatar
2 votes
2 answers
3k views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
coderodde's user avatar
  • 27k
6 votes
2 answers
600 views

Coding Challenge Solution - Good Range

This my solution to this Good Range Coding Challenge There is a number space given from 1 to N. And there are M queries followed by that. In each query, we were given a number between 1 to N (both ...
Nicola Bernini's user avatar
1 vote
1 answer
72 views

Python function to get numbers around another number

I made a function to get a list with numbers around another number. Example: I want to get in a range of 2 numbers around 4. This will return: [2, 6]. You can set a ...
Myzel394's user avatar
  • 296
4 votes
1 answer
82 views

Construct intervals from a sequence of numbers and vice versa

What is a Pythonic way to construct intervals from a sequence of integer numbers? E.g. sequence [1, 2, 3, 6, 7, 9] could be converted to ...
niekas's user avatar
  • 141
6 votes
2 answers
3k views

How to set an interval to std::map [closed]

This code belongs to a contest. I tried to apply the range of data to a std::map. The contest system however warns me that the implementation of the assign function ...
Mehrzad's user avatar
  • 77
6 votes
3 answers
2k views

Get consecutive integer number ranges from list of int

This is an algorithm to return a list of consecutive integer ranges from a list of integers. The practical use of such an algorithm is to filter lists more efficiently, i.e. rather than check e.g. ...
Aalawlx's user avatar
  • 193
2 votes
0 answers
31 views

Getting service rate based on time/day of service

I have a long roster where I'd like to categorize the rates by time/day of service. Most shifts ends the same date but there are some special cases where the shift ends on a different date. I have to ...
chase devilla's user avatar
8 votes
2 answers
1k views

Finding all intervals that match predicate in vector

I have a function find_all_intervals_below that iterates through a vector and finds all the index intervals of at least a given length where each element within the ...
Michael Hall's user avatar
5 votes
3 answers
831 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]) ...
C. E.'s user avatar
  • 153
4 votes
2 answers
255 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. ...
David Culbreth's user avatar
15 votes
3 answers
29k views

Checking if two time intervals overlap

I have two time intervals i1 and i2, each defined by two values, begin and ...
Eugene S's user avatar
  • 315
4 votes
1 answer
1k 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 ...
codingnoob's user avatar
7 votes
2 answers
3k 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 ...
pitchounet's user avatar
5 votes
4 answers
940 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). ...
HelloWorld's user avatar
5 votes
1 answer
484 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 ...
Philipp Mochine's user avatar
2 votes
0 answers
171 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. ...
ytfntk's user avatar
  • 21
2 votes
1 answer
725 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 ...
Latika Agarwal's user avatar
5 votes
3 answers
4k 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. ...
squeekyDave's user avatar
3 votes
3 answers
581 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 ...
Exploring's user avatar
  • 345
6 votes
3 answers
998 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 ...
MrA's user avatar
  • 333
8 votes
2 answers
2k 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 ...
Pig's user avatar
  • 345
-1 votes
1 answer
2k views

Maximum Difference in an Array [closed]

Maintain a minimum and max difference as we scan the input array. ...
saneGuy's user avatar
  • 373
2 votes
1 answer
1k 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 ...
Anirudh Thatipelli's user avatar
4 votes
0 answers
98 views

Biometric data representation in Java

This code represents biometric data averaged over a 1min period, beginning at the given UTC time. Please review my code: ...
Vatsala Sonal's user avatar
1 vote
0 answers
184 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 <...
bernhard_e's user avatar
1 vote
1 answer
440 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: ...
Leron's user avatar
  • 145