Skip to main content
Back to problems
Leetcode
Easy
Two Pointers
Strings
Is Subsequence

Check whether one string is a subsequence of another.

Acceptance 0%
Problem Statement

Problem

Given two strings s and t, determine whether s is a subsequence of t.

A string s is a subsequence of t if all characters of s appear in t in the same relative order, but not necessarily contiguously.

Return true if s is a subsequence of t; otherwise return false.

Notes

  • You may skip characters in t.
  • The characters of s must appear in order.
  • An empty string is a subsequence of any string.

Input Format

  • Two strings s and t.
  • s is the candidate subsequence.
  • t is the reference string to scan.

Output Format

  • Return a boolean value.
  • true if s is a subsequence of t, otherwise false.

Constraints

  • 0st0 \le |s| \le |t|
  • Strings contain lowercase English letters in the standard formulation of this problem.
  • Time complexity should be linear in the length of t.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "abc"
t = "ahbgdc"

Output

true

Explanation

You can match 'a', then 'b', then 'c' in order while skipping other characters in t.

Example 2

Input

s = "axc"
t = "ahbgdc"

Output

false

Explanation

There is no 'x' in t, so s cannot be formed as a subsequence.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.