Loading...
Loading...
You are given two strings s and t of equal length, both consisting of lowercase English letters. The vowels are a, e, i, o, u; every other letter is a consonant.
You want to replace some characters of s so that the result is an anagram of t, meaning every letter occurs the same number of times in both strings. Positions do not matter: a letter that already occurs the same number of times in s and t needs no work.
Each replacement of one character of s by a different letter has a cost that depends on the two letters' classes:
1;2.Return the minimum total cost to turn s into an anagram of t.
Input: s = "abc", t = "aei"
Output: 2
Explanation: a is already matched. The surplus letters b and c are consonants and the missing letters e and i are vowels, so each conversion crosses classes and costs 1: total 2.
Input: s = "ab", t = "cd"
Output: 3
Explanation: a (vowel) -> one of the missing consonants costs 1; b (consonant) -> the other missing consonant costs 2. Total 3.
Input: s = "listen", t = "silent"
Output: 0
Explanation: The strings are already anagrams of each other.
s.length = t.length ≤105s and t consist of lowercase English letters