There are N sheep relaxing in a field. They are positioned at points with integer coordinates. Each sheep has a square sunshade, so as not to overheat. The sunshade of a sheep standing at position (X, Y) spreads out to a distance of D from (X, Y), covering a square whose middle is at (X, Y) and whose sides are of length 2D. More precisely, it covers a square with vertices in points (X − D, Y − D), (X − D, Y + D), (X + D, Y − D) and (X + D, Y + D). Sheep are in the centres of their sunshades. Sunshades edges are parallel to the coordinate axes.
Every sheep spreads out its sunshade to the same width. No two sunshades can overlap, but their borders can touch.
What is the maximum integer width D to which the sheep can spread out their sunshades?
Write a function:
def solution(X, Y)
that, given two arrays X and Y of length N denoting the positions of the sheep, returns the maximum value of D to which the sheep can spread out their sunshades. There are at least two sheep in the flock, and no two sheep share a point with the same coordinates.
Examples:
1. Given X=[0, 0, 10, 10] and Y=[0, 10, 0, 10],

the function should return 5.
2. Given X=[1, 1, 8] and Y=[1, 6, 0],

the function should return 2.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [2..100,000];
- each element of arrays X and Y is an integer within the range [0..100,000];
- no two sheep are standing in the same position.
def solution(X, Y):
points = list(zip(X,Y))
points.sort()
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#
points = list(zip(X,Y))
points.sort()
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points that will be used
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all o
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is di
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points that have delta X or
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points that have delta X(and possible Delta Y)
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points with different X that have delta X(and possible Delta Y)
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points with different X that have delta X and Y smaller then minimum
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points with different X that have delta X and Y smaller then minimum
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points with different X that have delta X and Y smaller then minimum
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
def solution(X, Y):
#probably best way to unite and sort two arrays
points = list(zip(X,Y))
points.sort()
#creating empty dictonary P and finding distance beetween first two points
minimum=max((points[1][0]-points[0][0]),abs(points[1][1]-points[0][1]))
P ={}
#filling dictonary where is key is X coordinate and value is array with all Y coordinates with same X
for x in points:
if x[0] in P: P[x[0]].append(x[1])
else: P[x[0]] = [x[1]]
#getting all keys and storing them
xpoints=list(P.keys())
#loop that goes through all possible X coordinates. Some values stored in valuable for incresing speed.
for x in range(0,len(xpoints)):
ax=xpoints[x]
ypoints=P[ax]
#loop for Y coordinates
for y in range(0,len(ypoints)):
#finding closest point where is X same and only Y is different
if (y<len(ypoints)-1) and (ypoints[y+1]-ypoints[y]<minimum): minimum=ypoints[y+1]-ypoints[y]
ystart=ypoints[y]
yb1=ypoints[y]-minimum
yb2=ypoints[y]+minimum
m=x+1
#3rd loop for finding points with different X that have delta X and Y smaller then minimum
while (m<len(xpoints)) and (xpoints[m]-ax<minimum):
for z in sorted(x for x in P[xpoints[m]] if yb1<x<yb2):
minimum=max(abs(z-ystart), xpoints[m]-ax)
m +=1
return(minimum//2)
The solution obtained perfect score.