#K75697. Subsequence Verification
Subsequence Verification
Subsequence Verification
You are given two arrays of integers. The first array is the main array a and the second array is the candidate b. Your task is to determine whether b is a subsequence of a. A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements.
Definition: Array b is a subsequence of array a if there exists a sequence of indices i1, i2, ..., im such that 0 \le i1 < i2 < ... < im < n and for every j (1 ≤ j ≤ m), a[ij] = b[j].
Note: An empty sequence is considered a subsequence of any array.
inputFormat
The input is read from standard input and consists of three lines:
- The first line contains two space-separated integers n and m where n is the size of the main array and m is the size of the candidate subsequence.
- The second line contains n space-separated integers representing the main array a.
- The third line contains m space-separated integers representing the candidate subsequence b. If m is 0, this line will be empty.
outputFormat
Output a single line to standard output containing True
if b is a subsequence of a, and False
otherwise.
4 2
1 2 3 4
2 4
True