Approach: Given two sequence of numbers, start with two starting indexes, and increment second index if the element matched, keep incrementing the main array index always, at last check if the index of sequence is equal to count of sequence
public static bool IsValidSubsequence(List<int> array, List<int> sequence) {
// Write your code here.
int i = 0;
int j = 0;
while(i < array.Count && j < sequence.Count)
{
if(array[i] == sequence[j])
{
j ++;
}
i++;
}
return j == sequence.Count;
}