Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Equalize strings problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Equalize strings problem solution, You are given two binary strings A and B and are required to make A equals to B. There are two types of operations:
  1. Swap any two adjacent bits or characters in string A. The cost of this operation is 1 unit.
  2. 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?
 
 
HackerEarth Equalize strings problem solution

 

 

HackerEarth Equalize strings problem solution.

#include <iostream>
using namespace std;
long long i,n,s=0;
string a,b;
int main(){
cin>>n>>a>>b;
for(i=0;i<n;i++)
if(a[i]!=b[i]){
if(i<n-1&&a[i]==b[i+1]&&b[i]==a[i+1])
i++;
s++;
}
cout<<s;
return 0;
}
 

Second solution

n = int(input())
s = list(input())
p = list(input())
ans = 0
for i in range(0, n - 1):
if s[i] == p[i + 1] and s[i + 1] == p[i] and s[i] != s[i + 1]:
s[i], s[i + 1] = s[i + 1], s[i]
ans += 1
print(ans + sum(s[i] != p[i] for i in range(n)))
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes