Codeforces Round #825 (Div. 2) 1736A - Make A Equal to B Solution
Problem Link: https://codeforces.com/contest/1736/problem/A
Solution in C++:
/// La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
/// Abul Hasnat Tonmoy
/// Department of CSE,23rd batch
/// Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t, n, i;
cin >> t;
while (t--) {
cin >> n;
int a[n + 1], b[n + 1];
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) cin >> b[i];
vector<int> s1, s2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
s1.push_back(a[i]);
s2.push_back(b[i]);
}
}
int l;
l = s2.size();
int c1 = 0, c2 = 0;
for (i = 0; i < l; i++) {
if (s1[i] != s2[i]) {
c1++;
}
}
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
c2 = 1;
for (i = 0; i < l; i++) {
if (s1[i] != s2[i]) {
c2++;
}
}
cout << min(c1, c2) << endl;
}
}
No comments