2825. Make String a Subsequence Using Cyclic Increments Medium
1/**
2 * [2825] Make String a Subsequence Using Cyclic Increments
3 *
4 * You are given two 0-indexed strings str1 and str2.
5 * In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.
6 * Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.
7 * 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.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: str1 = "abc", str2 = "ad"
12 * Output: true
13 * Explanation: Select index 2 in str1.
14 * Increment str1[2] to become 'd'.
15 * Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
16 * <strong class="example">Example 2:
17 *
18 * Input: str1 = "zc", str2 = "ad"
19 * Output: true
20 * Explanation: Select indices 0 and 1 in str1.
21 * Increment str1[0] to become 'a'.
22 * Increment str1[1] to become 'd'.
23 * Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
24 * <strong class="example">Example 3:
25 *
26 * Input: str1 = "ab", str2 = "d"
27 * Output: false
28 * 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.
29 * Therefore, false is returned.
30 *
31 * Constraints:
32 *
33 * 1 <= str1.length <= 10^5
34 * 1 <= str2.length <= 10^5
35 * str1 and str2 consist of only lowercase English letters.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/
41// discuss: https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn can_make_subsequence(str1: String, str2: String) -> bool {
47 false
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2825() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.