Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • 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
Programmingoneonone

HackerEarth Equalize strings problem solution

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

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes