Check if a pair with given product exists in Linked list | Link list node ; Push a new node on the front of the list . ; Checks if pair with given product exists in the list or not ; Check if pair exits ; Driver Code ; Start with the empty list ; Use push ( ) to construct linked list ; function to print the result
class Node : NEW_LINE INDENT def __init__ ( self , data , next ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = next NEW_LINE DEDENT DEDENT class LinkedList : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . head = None NEW_LINE DEDENT def push ( self , new_data ) : NEW_LINE INDENT new_node = Node ( new_data , self . head ) NEW_LINE self . head = new_node NEW_LINE DEDENT def check_pair_product ( self , prod ) : NEW_LINE INDENT p = self . head NEW_LINE s = set ( ) NEW_LINE while p != None : NEW_LINE INDENT curr = p . data NEW_LINE if ( prod % curr == 0 and ( prod // curr ) in s ) : NEW_LINE INDENT print ( curr , prod // curr ) NEW_LINE return True ; NEW_LINE DEDENT s . add ( p . data ) ; NEW_LINE p = p . next ; NEW_LINE DEDENT return False NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT linkedlist = LinkedList ( ) NEW_LINE linkedlist . push ( 1 ) NEW_LINE linkedlist . push ( 2 ) NEW_LINE linkedlist . push ( 1 ) NEW_LINE linkedlist . push ( 12 ) NEW_LINE linkedlist . push ( 1 ) NEW_LINE linkedlist . push ( 18 ) NEW_LINE linkedlist . push ( 47 ) NEW_LINE linkedlist . push ( 16 ) NEW_LINE linkedlist . push ( 12 ) NEW_LINE linkedlist . push ( 14 ) NEW_LINE res = linkedlist . check_pair_product ( 24 ) NEW_LINE if res == False : NEW_LINE INDENT print ( " NO ▁ PAIR ▁ EXIST " ) NEW_LINE DEDENT DEDENT