Skip to content

Commit

Permalink
Create 2825. Make String a Subsequence Using Cyclic Increments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 4, 2024
1 parent 955df7a commit dc36b57
Showing 1 changed file with 28 additions and 0 deletions.
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();
}
};

0 comments on commit dc36b57

Please sign in to comment.