Given pointers to the head nodes of linked lists that merge together at some point, find the Node where the two lists merge. It is guaranteed that the two head Nodes will be different, and neither will be NULL.
In the diagram below, the two lists converge at Node x:
Complete the int findMergeNode(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) method so that it finds and returns the data value of the Node where the two lists merge.
Do not read any input from stdin/console.
The findMergeNode(SinglyLinkedListNode,SinglyLinkedListNode) method has two parameters, and , which are the non-null head Nodes of two separate linked lists that are guaranteed to converge.
The lists will merge.
Do not write any output to stdout/console.
Each Node has a data field containing an integer. Return the integer data for the Node where the two lists merge.
The diagrams below are graphical representations of the lists that input Nodes and are connected to. Recall that this is a method-only challenge; the method only has initial visibility to those Nodes and must explore the rest of the Nodes using some algorithm of your own design.
Test Case 0
Test Case 1
Test Case 0: As demonstrated in the diagram above, the merge Node's data field contains the integer . Test Case 1: As demonstrated in the diagram above, the merge Node's data field contains the integer .