#C8395. Common Element Finder
Common Element Finder
Common Element Finder
You are given an integer n and two sequences of n integers. The first sequence represents your numbers and the second sequence represents Alice's numbers. Your task is to identify the first element in the first sequence that also appears in the second sequence. If no such common element exists, output -1
.
Formally, given two sequences \(A = [a_1, a_2, \ldots, a_n]\) and \(B = [b_1, b_2, \ldots, b_n]\), find the smallest index \(i\) such that \(a_i \in B\). If there is no such \(a_i\), print \(-1\).
inputFormat
The input consists of three lines:
- The first line contains an integer \(n\) \((1 \leq n \leq 10^5)\).
- The second line contains \(n\) space-separated integers representing the first sequence.
- The third line contains \(n\) space-separated integers representing the second sequence.
outputFormat
Output a single integer: the first common element found in the first sequence that appears in the second sequence. If no such element exists, output -1
.
5
1 2 3 4 5
3 6 7 4 9
3