Skip to content

Create 2825. Make String a Subsequence Using Cyclic Increments #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
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