Binary Swap

3.5

16 votes
Algorithms, Easy, String Manipulation
Problem

You are given two binary strings A and B of equal length. You have a type of opertion in which you can swap any two elements of string B. Your task is to find the minimum number of operations required to convert string B into string A. If it is not possible, print -1.

Input Format:

First line contains string A.

Second line contains string B.

Output Format:

Print the minimum number of operations required to convert string B into string A. If it is not possible, print -1.

Constraints:

|A|=|B|;|S|referstolengthofstringS

1|A|105

Sample Input
1110
1101
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

You can swap the last and second last element in the string B. After swapping string B will become 1110. Therefore, only one operation is required to convert string B into string A.

Editor Image

?