compiler not give correct output
i tried other compiler the they gave correct output
Compiler not working properly
Hello @ABhinav-Kamboj-1196520907162943, have you tried this on hackerblocks ?? And in which language / on which testcase it is giving compilation issue , pls show your code
i use c++ on coding block’s platform problem - find majority elements , i use sample testcase which is given in problem
#include
using namespace std;
int main() {
int n;
int arr[n];
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
int e1=arr[0],count1=1,e3=-1,count2=0;
for(int i=1;i<n;i++){
if(arr[i]==e1){
count1++;
}else if(arr[i]==e3){
count2++;
}else if(count1==0){
e1=arr[i];
count1=1;
}else if(count2 == 0){
e3=arr[i];
count2=1;
}else{
count1--;
count2--;
}
}
int a=0,b=0;
for(int i=0;i<n;i++){
if(arr[i]==e1){
a++;
}
if(arr[i]==e3){
b++;
}
}
if(a>n/3){
cout<<e1;
}
if(b>n/3){
cout<<" "<<e3;
}
}
test case
9
2 2 2 2 1 1 2 3 4
After #include you forgot or <bits/stdc++.h> whatever you would like to use
no this is mistake during copy i use #include
answer it give is wrong
but correct in other compiler(ideone)
i think in this chat it not take after #include
can you pls provide your code using coding blocks ide
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.