The Is Subsequence interview question asks you to determine if string s is a subsequence of string t. A subsequence is a new string formed from the original string by deleting some (or no) characters without disturbing the relative positions of the remaining characters. (e.g., "abc" is a subsequence of "ahbgdc").
This is a standard question at Apple, Uber, and Microsoft. It tests basic Two Pointers logic and string traversal. For the "Hard" variation (checking multiple s strings against one t), it evaluations your ability to use Pre-processing and binary search to optimize the lookup.
This problem follows the Two Pointers interview pattern.
i = 0 (for s), j = 0 (for t).j < t.length:
s[i] == t[j], increment i (you found a match for the next character of the subsequence).j (to search the rest of the target string).i == s.length, all characters of s were found in order.s = "abc", t = "ahbgdc"
i=0(a), j=0(a). Match! i=1, j=1.i=1(b), j=1(h). No match. j=2.i=1(b), j=2(b). Match! i=2, j=3.i=2(c), j=3(g). No match. j=4.i=3. Return true.| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Palindromic Substrings | Medium | Solve | |
| Push Dominoes | Medium | Solve | |
| Longest Palindromic Substring | Medium | Solve | |
| Longest Palindrome After Substring Concatenation I | Medium | Solve | |
| Find the Lexicographically Smallest Valid Sequence | Medium | Solve |