| | | 1 | | // -------------------------------------------------------------------------------- |
| | | 2 | | // Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | | 3 | | // All Rights Reserved. |
| | | 4 | | // -------------------------------------------------------------------------------- |
| | | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | | 9 | | // known as Yevhenii Yeriemeieiv). |
| | | 10 | | // -------------------------------------------------------------------------------- |
| | | 11 | | |
| | | 12 | | namespace LeetCode.Algorithms.MakeStringSubsequenceUsingCyclicIncrements; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class MakeStringSubsequenceUsingCyclicIncrementsTwoPointers : IMakeStringSubsequenceUsingCyclicIncrements |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Time complexity - O(n + m) |
| | | 19 | | /// Space complexity - O(1) |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="str1"></param> |
| | | 22 | | /// <param name="str2"></param> |
| | | 23 | | /// <returns></returns> |
| | | 24 | | public bool CanMakeSubsequence(string str1, string str2) |
| | 3 | 25 | | { |
| | 3 | 26 | | if (str2.Length > str1.Length) |
| | 0 | 27 | | { |
| | 0 | 28 | | return false; |
| | | 29 | | } |
| | | 30 | | |
| | 3 | 31 | | var str1Index = 0; |
| | 3 | 32 | | var str2Index = 0; |
| | | 33 | | |
| | 10 | 34 | | while (str1Index < str1.Length && str2Index < str2.Length) |
| | 7 | 35 | | { |
| | 7 | 36 | | if (str1[str1Index] == str2[str2Index] || (str1[str1Index] == 'z' && str2[str2Index] == 'a') || |
| | 7 | 37 | | str1[str1Index] + 1 == str2[str2Index]) |
| | 4 | 38 | | { |
| | 4 | 39 | | str2Index++; |
| | 4 | 40 | | } |
| | | 41 | | |
| | 7 | 42 | | str1Index++; |
| | 7 | 43 | | } |
| | | 44 | | |
| | 3 | 45 | | return str2Index == str2.Length; |
| | 3 | 46 | | } |
| | | 47 | | } |