Skip to content

Instantly share code, notes, and snippets.

@jerryvig
Last active June 26, 2019 23:02
Show Gist options
  • Save jerryvig/95352e6f56e642cb91d52a53dfbeac89 to your computer and use it in GitHub Desktop.
Save jerryvig/95352e6f56e642cb91d52a53dfbeac89 to your computer and use it in GitHub Desktop.
WIP - Codility - Disc Intersections
def solution(A):
start_end_points = []
for i, r in enumerate(A):
start_end_points.append(((i - r), (i + r)))
end_start_points = list(start_end_points)
start_end_points.sort(key=lambda v: v[0])
end_start_points.sort(key=lambda v: v[1])
oc = 0
l = len(start_end_points)
for i in range(l-1):
for j in range(i+1, l):
if end_start_points[i][1] >= start_end_points[j][0]:
oc += 1
if oc > 10000000:
return -1
else:
break
return oc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment