All Tracks Algorithms String Algorithms Basics of String Manipulation Problem

Binary Swap
Tag(s):

Algorithms, Easy, String, String Manipulation

Problem
Editorial
Analytics

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| \; refers \; to \; length \; of \; string \; S\)

\(1 \le |A| \le 10^5\)

SAMPLE INPUT
1110
1101
SAMPLE OUTPUT
1
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.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

Tata Health

Challenge Name

Tata Health Java Hiring Challenge

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?