← 返回 jpmorgan 的题目列表Minimum Anagram Edits
类型:qbank
Compute the minimum number of character operations needed to make one string an anagram of another. One OA variant provides two strings directly; another splits a numeric string into two halves and compares those halves.
Requirements
Main variant: given two strings s1 and s2, return the minimum number of edits needed so one can be transformed into an anagram of the other.
Numeric-string variant: given one digit string, split it into two halves by length, then compute the minimum steps needed to make the two halves anagrams.
Treat the operation definition carefully. In the common HackerRank-style version, one replacement fixes one excess character in one half, so the answer is half the sum of absolute frequency differences when lengths match.
If lengths do not match in the two-string variant, clarify whether insertions/deletions are allowed or whether the case is invalid.
Notes
Use a frequency counter. The core signal is recognizing that order does not matter once the target is an anagram.
For equal-length strings with replacement operations, count the surplus characters on one side; do not double-count both directions.
The numeric-string split variant depends on correct midpoint handling. If the length is odd, ask whether the input is guaranteed even.
Preparation
Write both versions: min_steps(s1, s2) and min_steps_split(s).
Test equal strings, completely disjoint alphabets, duplicate-heavy strings, and odd-length input handling.