#C8622. Subsequence Checker
Subsequence Checker
Subsequence Checker
You are given two arrays of integers, \(A\) and \(B\). Your task is to determine whether \(B\) is a subsequence of \(A\). A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Definition: \(B\) is a subsequence of \(A\) if there exists a sequence of indices \(i_1, i_2, \ldots, i_m\) in \(A\) such that \(A[i_1] = B[0],\ A[i_2] = B[1], \ldots, A[i_m] = B[m-1]\) with \(i_1 < i_2 < \ldots < i_m\).
Print YES
if \(B\) is a subsequence of \(A\), otherwise print NO
.
inputFormat
The input is given from stdin in the following format:
- An integer \(n\) representing the number of elements in array \(A\).
- \(n\) space-separated integers representing array \(A\).
- An integer \(m\) representing the number of elements in array \(B\).
- If \(m > 0\), then \(m\) space-separated integers representing array \(B\). If \(m = 0\), this line will be empty.
outputFormat
Output a single line to stdout containing YES
if \(B\) is a subsequence of \(A\), or NO
otherwise.
5
1 2 3 4 5
3
1 3 5
YES