Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2486 - Append Characters to String to Make Subsequence\.

    Medium

    You are given two strings s and t consisting of only lowercase English letters.

    Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.

    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.

    Example 1:

    Input: s = "coaching", t = "coding"

    Output: 4

    Explanation: Append the characters "ding" to the end of s so that s = "coachingding". Now, t is a subsequence of s ("<ins> co </ins>aching<ins> ding </ins>"). It can be shown that appending any 3 characters to the end of s will never make t a subsequence.

    Example 2:

    Input: s = "abcde", t = "a"

    Output: 0

    Explanation: t is already a subsequence of s ("<ins> a </ins>bcde").

    Example 3:

    Input: s = "z", t = "abcde"

    Output: 5

    Explanation: Append the characters "abcde" to the end of s so that s = "zabcde". Now, t is a subsequence of s ("z<ins> abcde </ins>"). It can be shown that appending any 4 characters to the end of s will never make t a subsequence.

    Constraints:

    • <code>1 <= s.length, t.length <= 10<sup>5</sup></code>

    • s and t consist only of lowercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer appendCharacters(String s, String t)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait