You are given two binary strings \(A\) and \(B\) and are required to make \(A\) equals to \(B\). There are two types of operations:
- Swap any two adjacent bits or characters in string \(A\). The cost of this operation is 1 unit.
- Flip the bit or character of the string. The cost of this operation is 1 unit.
What is the minimum cost to make string \(A\) equal to \(B\)?
Input format
- The first line contains one integer that denotes the length of both strings.
- The next two lines take two strings \(A\) and \(B\) of length \(n\) as an input.
Output format
Print one integer that represents the minimum cost required to convert string \(A\) to string \(B\).
Constraints
\(1 \le n \le 10^{5}\)
Note
The length of both the strings \(A\) and \(B\) is always the same.
We will flip the first character which will cost us 1 unit. Now the string A will be "0101". We will swap second and third characters which will also cost us 1 unit.Now the string A will be "0011" which is same as B.Hence our total cost will be 2 units will be optimal.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor