Minimum Digit Changes Between String Halves
Problem statement
You are given an even-length string s that contains digits only. Split it into two equal halves.
In one operation, choose any position in the first half and replace its digit with any other digit from 0 through 9.
Return the minimum number of operations needed to make the first half an anagram of the second half.
Function
getAnagram(s: String) → intExamples
Example 1
s = "123212"return = 1The halves are 123 and 212. Replace digit 3 in the first half with 2, producing 122, which is an anagram of 212.
Example 2
s = "123456"return = 3The halves 123 and 456 share no digit. Every position in the first half must be replaced, so the minimum is 3.
Constraints
1 <= s.length <= 10^5s.lengthis a multiple of2.scontains digits only.