def detect_loop(lst):
# Write your code here
seen = set()
head = lst.get_head()
while head:
if head in seen:
return True
seen.add(head)
head = head.next_element
return False
Yes, it’s a valid approach that has been covered later on in the course in Hashing.