Skip to content

Commit c69a53c

Browse files
authored
Create 2825. Make String a Subsequence Using Cyclic Increments (#651)
2 parents 955df7a + dc36b57 commit c69a53c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution
2+
{
3+
public:
4+
bool canMakeSubsequence(string s, string t)
5+
{
6+
// Step 1: Initialize two pointers
7+
int j = 0; // Pointer for string t
8+
9+
// Step 2: Loop through string s
10+
for (int i = 0; i < s.size() && j < t.size(); i++)
11+
{
12+
// Step 3: Get the current character in s
13+
char current = s[i];
14+
15+
// Step 4: Compute the cyclic increment
16+
char next = (current == 'z') ? 'a' : (current + 1);
17+
18+
// Step 5: Check if current or its cyclic increment matches t[j]
19+
if (current == t[j] || next == t[j])
20+
{
21+
j++; // Move to the next character in t
22+
}
23+
}
24+
25+
// Step 6: If we have matched all characters of t, return true
26+
return j == t.size();
27+
}
28+
};

0 commit comments

Comments
 (0)