Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Minimum Number of Steps to Make Two Strings Anagram (medium)
On this page

Problem Statement

Examples

Try it yourself

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, and p characters in the string t to match the frequency of characters in s.

Example 2:

  • Input: s = "abc", t = "def"
  • Expected Output: 3
  • Justification: We need to replace all three characters in t to match those in s.

Example 3:

  • Input: s = "listen", t = "silent"
  • Expected Output: 0
  • Justification: The string t is already an anagram of s.

Constraints:

  • 1 <= s.length <= 5 * 10<sup>4</sup>
  • s.length == t.length
  • s and t 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