Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Intervals #104

Open
silverdrake11 opened this issue Nov 4, 2021 · 1 comment
Open

Merge Intervals #104

silverdrake11 opened this issue Nov 4, 2021 · 1 comment

Comments

@silverdrake11
Copy link
Contributor

No description provided.

@TannerHornsby7
Copy link

`
import itertools
def merge(intervals):
new_intervals = []
# Checking that the list of intervals given is longer than 1
# As if there is only one interval we just return the list
if (len(intervals) <= 1):
return intervals
# Now we can iterate through the list assigning the merged
# Values to our new_intervals list
for a, b in itertools.combinations(intervals, 2):
new_intervals = x_overlap_y(a, b)
print(new_intervals)

def x_overlap_y(x, y):
a = x[0]
b = x[1]
c = y[0]
d = y[1]
if ((a - c) * (b - d) > 0):
return [[a, b], [c,d]]
else:
front = c if (a - c > 0) else a
back = b if (b - d > 0) else d
return [front, back]
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants