Last active
June 26, 2019 23:02
-
-
Save jerryvig/95352e6f56e642cb91d52a53dfbeac89 to your computer and use it in GitHub Desktop.
WIP - Codility - Disc Intersections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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