← 返回 jpmorgan 的题目列表Minimum Steps to Make Two Halves Anagram (Numeric String)
类型:online_judge
Problem
Given a string s consisting only of digit characters (0-9).
If the length of s is odd, return -1.
Otherwise, split s into two equal halves:
a = s[0 : n/2]
b = s[n/2 : n]
You may perform replacement operations on characters in a: in one operation, replace any single character in a with any digit character (0-9).
Compute the minimum number of replacements needed so that a becomes an anagram of b (i.e., both halves have identical character counts).
Input (stdin)
One line: a string s.
Output (stdout)
Print an integer: the minimum number of operations, or -1 if |s| is odd.
Constraints
1 <= |s| <= 2 * 10^5
s contains only 0-9
Examples
Input: 123321 -> Output: 0
Input: 1212 -> Output: 0
Input: 10 -> Output: 1
Input: 123 -> Output: -1
Example
Input
123321
Output
0