Back to course home
0% completed
Vote For New Content
Minimum Number of Steps to Make Two Strings Anagram (medium)
Problem Statement
Given two strings, s
and t
, of the same length, return the minimum number of steps required to make t
an anagram of s
.
In each step, you can replace any character in t
with another character.
An anagram of a string is a string that contains the same characters in any order.
Examples
Example 1:
- Input: s = "designgurus", t = "garumdespgn"
- Expected Output: 3
- Justification: We need to replace
a
,m
, andp
characters in the stringt
to match the frequency of characters ins
.
Example 2:
- Input: s = "abc", t = "def"
- Expected Output: 3
- Justification: We need to replace all three characters in
t
to match those ins
.
Example 3:
- Input: s = "listen", t = "silent"
- Expected Output: 0
- Justification: The string
t
is already an anagram ofs
.
Constraints:
- 1 <= s.length <= 5 * 10<sup>4</sup>
s.length == t.length
s
andt
consist of lowercase English letters only.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself