161. Check if String is a Subsequence of Another

EasyStringString

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

A subsequence is a string derived from another string by deleting some or no characters without changing the relative order of the remaining characters.

Input: Two comma-separated strings: s and t.

Output: Return 'true' if s is a subsequence of t, otherwise 'false'.

Examples

Example 1
Input: abc,ahbgdc
Output: true
Explanation: a→h(skip)→b→g(skip)→d(skip)→c → found all of 'abc' in order.
Example 2
Input: axc,ahbgdc
Output: false
Explanation: After matching 'a' and needing 'x', 'x' is never found in t.
Example 3
Input: ,ahbgdc
Output: true
Explanation: Empty string is a subsequence of any string.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →