#C11265. Subsequence Checker
Subsequence Checker
Subsequence Checker
You are given two sequences of integers: a main sequence \(A\) and a subsequence candidate \(B\). Your task is to determine whether \(B\) is a subsequence of \(A\). A subsequence is defined as a sequence that can be derived from \(A\) by deleting some or no elements without changing the order of the remaining elements.
Formally, if \(A = [a_1, a_2, \dots, a_n]\) and \(B = [b_1, b_2, \dots, b_m]\), then \(B\) is a subsequence of \(A\) if there exists indices \(1 \leq i_1 < i_2 < \cdots < i_m \leq n\) such that \(b_1 = a_{i_1}, b_2 = a_{i_2}, \dots, b_m = a_{i_m}\).
Print YES if \(B\) is a subsequence of \(A\), otherwise print NO.
inputFormat
The input is given via standard input and consists of four lines:
- An integer \(n\) representing the number of elements in the main sequence \(A\).
- \(n\) space-separated integers representing the elements of \(A\).
- An integer \(m\) representing the number of elements in the subsequence candidate \(B\).
- \(m\) space-separated integers representing the elements of \(B\).
You can assume that \(0 \leq m \leq n\) and all integers fit within typical 32-bit signed integer limits.
outputFormat
Output a single line to standard output: YES if \(B\) is a subsequence of \(A\), or NO otherwise.
## sample5
1 2 3 4 5
2
2 4
YES
</p>