Help me in solving DSSA93A problem

My issue

Getting output as yes yes

My code

# cook your dish here
def can_visit_cities(N, D, C):
    sorted_cities = sorted(enumerate(C), key=lambda x: x[1])
    left_end, right_end = 0, 0
    visited = set()
    while right_end < N:
        if sorted_cities[right_end][1] - sorted_cities[left_end][1] > D:
            left_end += 1
            right_end += 1
    if len(visited) == N:
        return "YES"
        return "NO"

# Input reading
T = int(input())
for _ in range(T):
    N, D = map(int, input().split())
    C = list(map(int, input().split()))
    result = can_visit_cities(N, D, C)

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