Minimum Number of Steps to Make Two Strings Anagram
MediumArrays & Hashinghashing
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given two lowercase strings s and t of the same length. In one step you may replace any single character of t with any lowercase letter.
Return the minimum number of steps needed to make t an anagram of s, meaning t contains exactly the same letters with the same counts, in any order.
Examples
Input: s = "listen", t = "silent"
Output: 0
`t = "silent"` already uses the same letters as `s = "listen"`.
Input: s = "world", t = "hello"
Output: 3
`s = "world"` and `t = "hello"` share one `l` and one `o`; the other three letters of `t` must change.
Input: s = "abb", t = "aab"
Output: 1
`s` has two `b`s but `t` has only one, so one extra `a` in `t` must become `b`.
Constraints
- 1 <= s.length <= 5 * 10^4
- s.length == t.length
- s and t consist of lowercase English letters
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.