Class Solution
-
- All Implemented Interfaces:
public final class Solution2825 - Make String a Subsequence Using Cyclic Increments\.
Medium
You are given two 0-indexed strings
str1andstr2.In an operation, you select a set of indices in
str1, and for each indexiin the set, incrementstr1[i]to the next character cyclically. That is'a'becomes'b','b'becomes'c', and so on, and'z'becomes'a'.Return
trueif it is possible to makestr2a subsequence ofstr1by performing the operation at most once, andfalseotherwise.Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.
Example 1:
Input: str1 = "abc", str2 = "ad"
Output: true
Explanation: Select index 2 in str1. Increment str12 to become 'd'. Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
Example 2:
Input: str1 = "zc", str2 = "ad"
Output: true
Explanation: Select indices 0 and 1 in str1. Increment str10 to become 'a'. Increment str11 to become 'd'. Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
Example 3:
Input: str1 = "ab", str2 = "d"
Output: false
Explanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once. Therefore, false is returned.
Constraints:
<code>1 <= str1.length <= 10<sup>5</sup></code>
<code>1 <= str2.length <= 10<sup>5</sup></code>
str1andstr2consist of only lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleancanMakeSubsequence(String str1, String str2)-
-
Method Detail
-
canMakeSubsequence
final Boolean canMakeSubsequence(String str1, String str2)
-
-
-
-