2486. Append Characters to String to Make Subsequence Medium
1/**
2 * [2486] Append Characters to String to Make Subsequence
3 *
4 * You are given two strings s and t consisting of only lowercase English letters.
5 * Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.
6 * A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: s = "coaching", t = "coding"
11 * Output: 4
12 * Explanation: Append the characters "ding" to the end of s so that s = "coachingding".
13 * Now, t is a subsequence of s ("<u>co</u>aching<u>ding</u>").
14 * It can be shown that appending any 3 characters to the end of s will never make t a subsequence.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: s = "abcde", t = "a"
19 * Output: 0
20 * Explanation: t is already a subsequence of s ("<u>a</u>bcde").
21 *
22 * <strong class="example">Example 3:
23 *
24 * Input: s = "z", t = "abcde"
25 * Output: 5
26 * Explanation: Append the characters "abcde" to the end of s so that s = "zabcde".
27 * Now, t is a subsequence of s ("z<u>abcde</u>").
28 * It can be shown that appending any 4 characters to the end of s will never make t a subsequence.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= s.length, t.length <= 10^5
34 * s and t consist only of lowercase English letters.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/
40// discuss: https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn append_characters(s: String, t: String) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2486() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.