importsysfromtypingimportListdefsolution(heights:List[int])->int:answer=0# 첫번째 통나무랑 마지막 통나무랑 인접하다는 것을 기억해야 됨
# 그럼 큰 것을 기준으로 해서 좌, 우로 작은 것들을 계속 배치해나간다면 최소가 됨
heights.sort()foriinrange(2,len(heights)):answer=max(answer,abs(heights[i]-heights[i-2]))returnanswerT=int(sys.stdin.readline().rstrip())for_inrange(T):N=int(sys.stdin.readline().rstrip())heights=list(map(int,sys.stdin.readline().rstrip().split()))print(solution(heights))
Leave a comment