#K1651. Subsequence Verification
Subsequence Verification
Subsequence Verification
You are given two arrays of integers. Your task is to determine whether the second array is a subsequence of the first array.
A sequence \( S \) is called a subsequence of an array \( A \) if there exists a sequence of indices \( \{i_1, i_2, \ldots, i_k\} \) such that \( 1 \leq i_1 < i_2 < \cdots < i_k \leq n \) and \( S = [A_{i_1}, A_{i_2}, \ldots, A_{i_k}] \). In other words, you can obtain \( S \) by removing zero or more elements from \( A \) without changing the order of the remaining elements.
Given two arrays, output "YES" if the second array is a subsequence of the first, otherwise output "NO".
inputFormat
The input is given via standard input and has the following format:
n A1 A2 ... An m B1 B2 ... Bm
Where:
- \( n \) is the number of elements in the first array.
- \( A1, A2, \ldots, An \) are the elements of the first array.
- \( m \) is the number of elements in the second array.
- \( B1, B2, \ldots, Bm \) are the elements of the second array.
outputFormat
Print a single line containing either "YES" if the second array is a subsequence of the first array, or "NO" otherwise.
## sample5
1 2 3 4 5
3
2 4 5
YES