# 817

from utils.listNode import ListNode

class Solution:
    # time: O(len of linked list)
    # space: O(len of G)
    def get_connected_count(self, head, G):
        count = 0

        if not head:
            return count
        
        values_set = set(G)

        prev = ListNode(None)
        prev.next = head

        while prev.next:
            if prev.value not in values_set and prev.next.value in values_set:
                count += 1
            
            prev = prev.next
        
        return count

zero = ListNode(0)
one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)
five = ListNode(5)

zero.next = one
one.next = two
two.next = three
three.next = four
four.next = five

print(zero)
G = [0, 3, 1, 4]
print(G)


solution = Solution()
print(solution.get_connected_count(zero, G))
            

