Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int arr[n];
set<int> st;
for(int i = 0; i < n; i++){
cin>>arr[i];
st.insert(arr[i]);
}
int sub = n - st.size();
if(sub%2){
sub++;
}
cout<<n-sub<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
4
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000
Output
2
1
2
4
1
2
4
Demonstration
Codeforcess Solution 1692-BB. All Distinct ,C++, Java, Js and Python , 1692-B,Codeforcess Solution