BackmediumArrays

Is Subsequence Solution

Problem Statement

Given two arrays of characters `arr` and `sub`, determine if `sub` is a subsequence of `arr`. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

Example 1
Input
arr = ["a", "b", "c", "d", "e", "f"], sub = ["a", "c", "e"]
Output
true

Explanation: All elements of sub ["a", "c", "e"] appear in arr in the same relative order, so it is a subsequence.

Constraints

  • 0 <= arr.length <= 10^5
  • 0 <= sub.length <= 10^4
  • Characters consist of lowercase English letters.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free