For code using intervals to measure “distance” between values, possibly as input, output, or in method calls.
5
votes
1answer
62 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
141 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 ...
0
votes
0answers
16 views
2
votes
1answer
58 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
107 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
18 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
28 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:
...
0
votes
0answers
64 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.
...
2
votes
1answer
58 views
“Can a list of meetings all be scheduled in a conference room?”
I was given this question at an interview for a position I just got rejected by, so looking to improve and see what better answers there are!
...
5
votes
2answers
101 views
Basic Scheduler, codingame 'Super Computer' Challenge
I have built a program that handles the basic scheduling requests for CodinGame's Super Computer challenge.
Specifications (taken from CodinGame)
The Goal
In ...
7
votes
1answer
99 views
Counting the overlapping intervals in the union of two sets
I had to recently implement a code to count the union of all intervals (if there are overlapping intervals) for an interview. I was provided with the following function stub:
...
9
votes
2answers
385 views
Finding the busiest time-frame in a parking lot
The text file containing cars' arrival and departure time will upload stuff from the parking lot.
Text will be like this:
...
3
votes
1answer
33 views
Searching the number with the biggest amount of odd divisors in an interval
I wrote this program for school (first year in college) and it works, but it's too slow. I wondered if anyone could help me optimize this a bit, because I've been trying and trying, but it just won't ...
2
votes
3answers
89 views
Checking if a value is within a time range
How can I improve the style to avoid so many float64()s?
...
4
votes
2answers
104 views
Representing and Parsing an Open or Closed Range
I would like to represent a numeric range in C#. Either open-ended, such as "up to 35" or "100 on up" or closed-ended, such as "34 to 65". I'd like to represent the open end with NULL. Further, I'd ...
2
votes
2answers
180 views
Checking overlap ranges between two prices
I have a method (C#, .NET framework 4.0) to check overlapping ranges between two prices.
I have a process, which will have one or more ...
2
votes
2answers
57 views
Merging an overlapping collection of intervals
I'm getting myself acquainted with Rust and decided to implement the classical overlapping intervals problem.
Here is a statement of the problem:
Given a collection of intervals, write a ...
8
votes
2answers
205 views
Parsing a list of single numbers and number ranges
I have input of a string containing a single number (like: \$3\$) or a range (like: \$1-5\$). Sample input, all together, looks like: "1-5,3,15-16", and sample ...
-1
votes
2answers
70 views
Rounding and truncation in IntRange.contains(Object o)
I made a Range class (like an Interval) that takes Integers and implements ...
3
votes
1answer
43 views
Merge adjacent numeric intervals
Given a list of pairs of integers that represent closed numeric intervals, I need to output a list of intervals where the adjacent intervals are merged together. The code assumes that the intervals do ...
5
votes
1answer
279 views
Combine a set of “ranges” to find least number of ranges
Given a set of ranges with lower bound and upper bound, I need to combine these ranges to produce minimum number of ranges which will cover all the values in the original set and nothing else.
...
1
vote
1answer
59 views
Find disjoint integer intervals
Given a list of numeric intervals in the form of (a,b), where a and b are integers, it finds ...
-2
votes
1answer
50 views
Checking whether the some of two ranges falls within a lower and upper bound
Problem 4
As per the given link, this exercise is part of recursion lab.
Printer A prints a random x copies 50 ≤ x ≤ 60, and Printer B prints a random y ...
5
votes
1answer
172 views
A Range object for Java that partially implements `List`
I'm writing a neural net which uses a genetic algorithm to adjust the weights. To represent the possible range of "genes" for the GA, I'm passing in a list of bases. Unfortunately, I realized after ...
3
votes
1answer
136 views
Interval scheduling problem in C++
The problem I attempted to solve is described as:
What is the largest subset of mutually non-overlapping intervals which
can be selected from I? Where I is a set of N intervals where each
...
3
votes
2answers
108 views
Lazily combine ranges dependent on modulo with one loop
I have a positive integer n. I want to lazily loop over a range of integers less than n consisting of a) integers divisible by 3 ...
1
vote
0answers
63 views
Array slice type in Java - follow-up
See the previous iteration.
I have essentially fixed most of the issues mentioned by maaartinus. However, I left the size field as it is. Namely, if the user wants ...
3
votes
1answer
331 views
Array slice type in Java
Edit See the next iteration at Array slice type in Java - follow-up.
I have this "slice" type for managing array subranges. It is kind of the same thing as Pythons slice notation, yet I did not add ...
2
votes
1answer
73 views
Sum of squares of each interval
Q. Write three similar functions, each of which takes as an argument a sequence of intervals and returns the sum of the square of each interval that does not contain 0.
Using a for ...
0
votes
1answer
117 views
Interval multiplication - faster version
For the below given problem from this assignment:
Q4. In passing, Ben also cryptically comments, "By testing the signs of the endpoints of the intervals, it is possible to break ...
5
votes
3answers
415 views
Model interval inclusiveness in C#
This is my first attempt to model a day's time interval and the fact that the start and end are either inclusive or not:
...
1
vote
2answers
80 views
Counting only weekend days between two timestamps
I am fairly new to the Groovy arena. I recently modified some code to add the following block. This code is added to remove dates we were supposed to remove from the total counts. This data goes on ...
7
votes
1answer
101 views
Onion Run Festival (or the unexpected anagram for Union of Intervals)
Original question: Union of intervals
In the original code, the Interval model class implements Comparable so that an input of ...
4
votes
1answer
199 views
Union of intervals
I am trying to solve for the problem with a bunch of intervals:
(1,2),(2,5),(4,7),(9,11)
I find their union, which in the above given case would be:
...
2
votes
1answer
21 views
1-D intersection of lines given begin and end points
I have a fairly basic question here: I want to find if two lines on a 1-D plane intersect. I know of two simple ways to solve this, but I wanted to know if Python has a more elegant way to solve this.
...
8
votes
4answers
2k views
Calculating range of ArrayLists
I have written this method which calculates the range (max - min) of an ArrayList. I have two for loops each for a different ...
4
votes
4answers
1k views
Aggregate array values into ranges
In five minutes I made a pretty ugly looking function. Can you help before I have to commit the code into history?
Requirements:
I would like a function that takes an array of numbers, and ...
4
votes
1answer
48 views
Average interval between dates with random blanks - follow-up
Original question:
Average interval between dates with random blanks
I have a spreadsheet with order date data:
I need to find the average interval in days between each order date. I have to ...
5
votes
2answers
248 views
VSTO Write Dictionary To Range Extension Method
I was hoping to receive some criticism on this block of code. I wrote it to write the contents of a dictionary to excel range in VSTO. It works well. I am interested to see how people could improve ...
4
votes
1answer
79 views
Average interval between dates with random blanks
I have a spreadsheet with order date data:
I need to find the average interval in days between each order date. I have to both find a way to get past the blank cells in the row, and also take into ...
2
votes
1answer
207 views
Formatting a date range, with shortening if the interval falls entirely within a calendar month
The graphic guy wants to display dates like
16. February
17. - 24. February, or
...
5
votes
3answers
3k views
Vertical Histogram
I've been been working on a vertical histogram that prints an asterisk in place of a number in a certain range (say 1-10... and so on). My code is working as required.
Is there a better, simpler or ...
5
votes
1answer
131 views
Store CMTimeRange into Core Data
I wanted to store CMTimeRange structures inside managed objects, so I've worked out the following:
...
2
votes
1answer
42 views
Sane ranges for DB queries
I have a function that has, as input, a ranges object which may define from, to and ...
6
votes
4answers
3k views
Finding overlapping time intervals
You have two lists with meetings scheduling (start time, end time). Meetings in single list don't intersect. Find all intersecting meetings across the two lists.
Is my complexity \$O(N M)\$? If I ...
3
votes
2answers
129 views
Reservation validation
I got a Reservation model that has reservation_start and reservation_end.
Then I have the ...
8
votes
1answer
198 views
consecutive_find function for returning a consecutive range of elements
consecutive_find() is a function that returns the beginning of a range that contains strictly N consecutive elements. It was part of a SO question that I answered.
...
1
vote
2answers
335 views
Double Inclusive Range step by step
I've written a method to obtain an IEnumerable from a start point, end point and step. Similar to Enumerable.Range() but for doubles and not fixed step.
...
8
votes
4answers
3k views
Merging Overlapping Intervals
A while back I was asked the following question in a phone interview, and to be honest it stumped me. After many long nights of rolling the problem around in my head I think I came up with a decent ...
11
votes
2answers
881 views
CodeEval's SkyScrapers challenge
This is a solution to CodeEval's SkyScrapers challenge.
You are given a list of triples \$(l, h, r)\$. Each triple represents an axis-aligned rectangle, with top-left corner at \$(l, h)\$ and ...