Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
405 B
1
Indexable
Never
import java.util.*;

class Program {
  public static boolean isValidSubsequence(List<Integer> array, List<Integer> sequence) {
		
		int j = 0;
		for (int i = 0; i < array.size(); i++) {
			if (j >= sequence.size()) {
				break;
			}
			int curr = array.get(i);
			if (curr == sequence.get(j)) {
				j++;
			}
		}
    return j == sequence.size();
  }
}

/*
ex1:
a=[5,1,22,25,6,-1,8,10]
s=[1,6,-1,10]




*/