Whats wrong in my subsequence validation?
Your loop on j (for j in range(i, len(array)):
) starts at an index that corresponds to a position in sequence. Advancing through array must be independent of the index of values in sequence.
You can do this with an iterator:
array=[5, 1, 22, 25, 6, -1, 8, 10]
sequence= [1, 6, -1, 10]
iArray = iter(array)
isSubsequence = all(s in iArray for s in sequence)
print(isSubsequence) # True
The s in iArray
part advances the iterator (iArray) up to the point where s is found. If array contains all the elements of sequence in the same order, then every s in sequence will be able to advance to a matching value in iArray.