DSA · Two Pointers · #91
Is Subsequence
Module 69 · difficulty 2/5·⏱ 30:00starts on first keystroke
Given two strings `s` and `t`, return `true` if `s` is a subsequence of `t`, and `false` otherwise. A subsequence of a string is a new string formed from the original by deleting some (possibly zero) characters without changing the relative order of the remaining characters. For example, `"ace"` is a subsequence of `"abcde"`. Implement `function isSubsequence(s, t)` returning a boolean.
Examples
s = "abc", t = "ahbgdc"→true— a, b, c appear in order within t.s = "axc", t = "ahbgdc"→false— x never appears, so s cannot be a subsequence.s = "", t = "ahbgdc"→true— The empty string is a subsequence of any string.
Constraints
- · 0 <= s.length <= 100
- · 0 <= t.length <= 10^4
- · s and t consist only of lowercase English letters.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.