ExamAdda Logo

Is Subsequence

Easy

Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

A subsequence of a string is formed by deleting zero or more characters from the original string without changing the relative order of the remaining characters.

Example 1

Input

abc
ahbgdc

Output

true

Explanation

The characters 'a', 'b', and 'c' appear in the same relative order in the string "ahbgdc".

Therefore, "abc" is a subsequence of "ahbgdc".

Example 2

Input

axc
ahbgdc

Output

false

Explanation

The character 'x' does not appear in the string "ahbgdc", so "axc" is not a subsequence.

Constraints

0 ≤ s.length ≤ 100
0 ≤ t.length ≤ 10⁴
Both strings consist only of lowercase English letters.

Hints:

Hint 1

Use one pointer for s and another for t.

Hint 2

Traverse t from left to right. Whenever characters match, move the pointer in s. If you reach the end of s, then s is a subsequence of t.

Follow-up

Similar Questions

  • Valid Palindrome
  • Longest Common Prefix
  • Two Sum II - Input Array Is Sorted
  • Longest Increasing Subsequence

 

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 4, 2026

Last updated

Aug 6, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output