Help me in solving DSSA93A problem

My issue

Could you please help me to complete Travelling salesman problems …

My code

# cook your dish here
t=int(input())
for _ in range(t):
    n,d=[int(i) for i in input().split()]
    checkright2=True
    checkleft2=True
    check1=True
    c=[int(i) for i in input().split()]
    startpoint=c[0]
    c.sort()
    for i in range(n-1):
        if (c[i+1]-c[i])>d:
            check1=False
            break
    startindex=c.index(startpoint)
    if startindex!=n-1 and startindex!=0 and check1:
        for i in range(startindex):
            if (c[i+2]-c[i])>d:
                checkleft2=False
                break
        if checkleft2==False:
            for i in range(startindex-1,n-2):
                if (c[i+2]-c[i])>d:
                    checkright2=False
                    break
    if (checkright2 or checkleft2) and check1:
        print('YES')
    else:
        print('NO')

Learning course: Kalasalingam Academy of Research and Education
Problem Link: CodeChef: Practical coding for everyone