My issue
This was the code that I wrote whilst the competition and I was getting wrong answer. I don’t understand what was wrong in this code. After seeing the hints, I submitted a different code for which I got Correct answer. Although, the approach is different, the logic remained the same.
My code
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
// your code goes here
lli t;
cin>>t;
while(t--) {
lli n;
cin>>n;
vector<lli> v;
lli runways = 1;
for (lli i = 0; i < n*2; i++) {
lli temp;
cin>>temp;
v.push_back(temp);
}
sort(v.begin(),v.end());
lli curr,count;
for (lli i = 0; i < n*2; i++) {
if (i == 0) {
curr = v[i];
count = 1;
}
else if (v[i] == curr) {
count++;
} else if (v[i] != curr) {
if (count > runways) runways = count;
count = 1;
curr = v[i];
}
}
cout<<runways<<"\n";
}
return 0;
}
Problem Link: AIRM Problem - CodeChef