Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Nov 28, 2023
1 parent 152941d commit 87acad3
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Runtime: O(n)
// Space: O(1)

function isValidSubsequence(array, sequence) {
let p1 = 0;
let p2 = 0;

while (p1 < array.length && p2 < sequence.length) {
if (array[p1] === sequence[p2]) {
p1++;
p2++;
} else {
p1++;
}
}

return p2 === sequence.length;
}

0 comments on commit 87acad3

Please sign in to comment.