Minimum Number of Steps to Make Two Strings Anagram II

You are given two strings s and t. In one step, you can append any character to either s or t.

Return the minimum number of steps to make s and t anagrams of each other.

An anagram of a string is a string that contains the same characters with a different (or the same) ordering.

Example 1
Inputs = "leetcode", t = "coats"
Output7
Appending "as" to s and "leede" to t makes the strings anagrams using 2 + 5 = 7 steps, and no fewer steps can work.
Example 2
Inputs = "night", t = "thing"
Output0
The given strings are already anagrams of each other, so no further steps are needed.

Constraints

  • 1 <= s.length, t.length <= 2 * 10^5
  • s and t consist of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate