144. Where Two Lists Join
Read two lists. Then read one more integer j.
If j is -1 the lists stay separate. Otherwise the last node of the SECOND list is made
to point at the node at 0-based position j of the first, so the two lists join and share
a tail.
Print the value of the first shared node, or -1 if they never join.
Constraints - `0 ≤ n, m ≤ 100000` - `-1 ≤ j < n` - `-1000000 ≤ value ≤ 1000000`
Input
The first line contains n, then a line of n integers — the first list.
The next line contains m, then a line of m integers — the second list.
The starter code builds both lists for you.
A final line contains an integer j. If j is -1 the lists stay separate; otherwise the last node of the SECOND list is linked to the node at 0-based position j of the first.
Output
Print one integer — the value of the first shared node, or -1 if the lists never join.