Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findCommonPart(s1, s2):
- common = (max(s1[0], s2[0]), min(s1[1], s2[1]))
- if common[0] > common[1]:
- return None
- return common
- def dist(s):
- return abs(s[1] - s[0])
- def solution(segments):
- target = 0
- otherTarget = None
- common = segments[0]
- for i, s in enumerate(segments[1:], 1):
- newCommon = findCommonPart(common, s)
- if not newCommon:
- if not otherTarget:
- otherTarget = i
- else:
- return target
- else:
- if dist(newCommon) < dist(common):
- target = i
- common = newCommon
- return otherTarget
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement