← Back to challenges

Validate Subsequences

JavaScriptHardloopsalgorithmsvalidation

Instructions

Given two non-empty lists, write a function that determines whether the second array is a subsequence of the first array.

For instance, the numbers [1, 3, 4] form a subsequence of the array [1, 2, 3, 4], and so do the numbers [2, 4].

Examples

isValidSubsequence([1, 1, 6, 1],[1, 1, 1, 6]) ➞ false

isValidSubsequence([5, 1, 22, 25, 6, -1, 8, 10], [22, 25, 6]) ➞ true

isValidSubsequence([1, 2, 3, 4], [2, 4]) ➞ true

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.