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

HackerEarth Equalize strings problem solution

YASH PAL, 31 July 202411 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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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