Equalize strings
Practice
2.8 (9 votes)
Greedy algorithms
Algorithms
String
Basics of greedy algorithms
Problem
94% Success 3975 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code
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.
Submissions
Please login to view your submissions
Similar Problems
Points:10
14 votes
Tags:
Basic ProgrammingAlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:10
3 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsSortingAlgorithmsMerge Sort
Points:10
11 votes
Tags:
HashingGreedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Editorial