LeetCode solutions

3018. Make String a Subsequence Using Cyclic Increments

My accepted C++ solution to LeetCode problem 3018, Make String a Subsequence Using Cyclic Increments, running in 3ms.

  • Difficulty: Medium
  • C++
  • Runtime 3ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 3ms, memory 17.2MB, accepted 2025-12-27.

cpp
class Solution {
    public:
    bool canMakeSubsequence(string str1, string str2) {
        int j = 0;
        for (int i = 0; i < str1.size() && j < str2.size(); i++) {
            if (str1[i] == str2[j] || (str1[i] - 'a' + 1) % 26 == str2[j] - 'a') {
                j++;
            }
        }
        return j == str2.size();
    }
};

Source