Two Sequences Subsequence Checking¶
Table of Contents¶
- 392. Is Subsequence (Easy)
- 524. Longest Word in Dictionary through Deleting (Medium)
- 2486. Append Characters to String to Make Subsequence (Medium)
- 2825. Make String a Subsequence Using Cyclic Increments (Medium)
- 1023. Camelcase Matching (Medium)
- 3132. Find the Integer Added to Array II (Medium)
- 522. Longest Uncommon Subsequence II (Medium)
- 1898. Maximum Number of Removable Characters (Medium)
- 2565. Subsequence With the Minimum Score (Hard)
- 3302. Find the Lexicographically Smallest Valid Sequence (Medium)
392. Is Subsequence¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: two pointers, string, dynamic programming
# DP - LCS
def isSubsequenceLCS(s: str, t: str) -> bool:
m = len(s)
n = len(t)
if m > n:
return False
dp = [[0] * (n + 1) for _ in range(m + 1)]
length = 0
for i in range(1, m + 1):
for j in range(1, n + 1):
if s[i - 1] == t[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = dp[i][j - 1] # only delete t string
if length < dp[i][j]:
length = dp[i][j]
return length == m
# Two Pointers
def isSubsequenceTP(s: str, t: str) -> bool:
i, j = 0, 0
while i < len(s) and j < len(t):
if s[i] == t[j]:
i += 1
j += 1
return i == len(s)
s = "abc"
t = "ahbgdc"
print(isSubsequenceLCS(s, t)) # True
print(isSubsequenceTP(s, t)) # True
524. Longest Word in Dictionary through Deleting¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, string, sorting
2486. Append Characters to String to Make Subsequence¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: two pointers, string, greedy
2825. Make String a Subsequence Using Cyclic Increments¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: two pointers, string
1023. Camelcase Matching¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, string, trie, string matching
3132. Find the Integer Added to Array II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, sorting, enumeration
522. Longest Uncommon Subsequence II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, hash table, two pointers, string, sorting
1898. Maximum Number of Removable Characters¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, string, binary search
2565. Subsequence With the Minimum Score¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: two pointers, string, binary search
3302. Find the Lexicographically Smallest Valid Sequence¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: two pointers, string, dynamic programming, greedy