Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 2825. Make String a Subsequence Using Cyclic Increments
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution
{
public:
bool canMakeSubsequence(string s, string t)
{
// Step 1: Initialize two pointers
int j = 0; // Pointer for string t

// Step 2: Loop through string s
for (int i = 0; i < s.size() && j < t.size(); i++)
{
// Step 3: Get the current character in s
char current = s[i];

// Step 4: Compute the cyclic increment
char next = (current == 'z') ? 'a' : (current + 1);

// Step 5: Check if current or its cyclic increment matches t[j]
if (current == t[j] || next == t[j])
{
j++; // Move to the next character in t
}
}

// Step 6: If we have matched all characters of t, return true
return j == t.size();
}
};
Loading