Check if a pair with given product exists in Linked list | JavaScript code to find the pair with given product ; Link list node ; Given a reference ( pointer to pointer ) to the head of a list and an int , push a new node on the front of the list . ; Function to check if pair with given product exists in the list Takes head pointer of the linked list and product ; Check if pair exits ; Start with the empty list ; Use push ( ) to construct linked list ; function to print the result
var MAX = 100000 ; class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } function check_pair_product ( head , prod ) { var s = [ ] ; var p = head ; while ( p != null ) { var curr = p . data ; if ( prod % curr == 0 && s . includes ( prod / curr ) ) { document . write ( curr + " " + prod / curr ) ; return true ; } s . push ( p . data ) ; p = p . next ; } return false ; } var head = null ; head = push ( head , 1 ) ; head = push ( head , 2 ) ; head = push ( head , 1 ) ; head = push ( head , 12 ) ; head = push ( head , 1 ) ; head = push ( head , 18 ) ; head = push ( head , 47 ) ; head = push ( head , 16 ) ; head = push ( head , 12 ) ; head = push ( head , 14 ) ; var res = check_pair_product ( head , 24 ) ; if ( res == false ) document . write ( " " ) ;