From dc36b577fc6906a38cb4c2d4184e932647d660b0 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Wed, 4 Dec 2024 20:12:27 +0530 Subject: [PATCH] Create 2825. Make String a Subsequence Using Cyclic Increments --- ...ring a Subsequence Using Cyclic Increments | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 2825. Make String a Subsequence Using Cyclic Increments diff --git a/2825. Make String a Subsequence Using Cyclic Increments b/2825. Make String a Subsequence Using Cyclic Increments new file mode 100644 index 0000000..2d50a98 --- /dev/null +++ b/2825. Make String a Subsequence Using Cyclic Increments @@ -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(); + } +};