Created
August 18, 2020 05:22
-
-
Save misterpoloy/7426e48ba2aca1e3dd0e47253cc693b5 to your computer and use it in GitHub Desktop.
Validate Subsequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace std; | |
// Repasado 2 veces | |
bool isValidSubsequence(vector<int> array, vector<int> sequence) { | |
int i = 0; | |
int seqIndex = 0; | |
while (i < array.size()) { | |
cout << "top= " << array[i] << endl; | |
cout << "sequence= " << sequence[seqIndex] << endl; | |
if (array[i] == sequence[seqIndex]) { | |
i++; | |
seqIndex++; | |
cout << "SIIIIIIIIII total= " << seqIndex << endl; | |
} else { | |
i++; | |
} | |
} | |
cout << "sequence size" << sequence.size() << endl; | |
return seqIndex == sequence.size(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Validate Subsequence
(Determine wether a sequence is a subsequence of the original array) eg, [a, c, d, f] it's a subsequence of [a, b, c, d, e, f].
**hint:**We can use pointers, a left for the subsequence and a second for the final array, if don't increment the pointer of the array.