# Can anyone tell what is wrong in this code?

**URL:** <https://discuss.codechef.com/t/can-anyone-tell-what-is-wrong-in-this-code/104108>\
**Category:** tutorial\
**Tags:** array, c-plus-plus\
**Created:** [November 16, 2022, 5:35pm UTC](https://discuss.codechef.com/t/can-anyone-tell-what-is-wrong-in-this-code/104108 "2022-11-16T17:35:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eitpw\_03](https://discuss.codechef.com/user_avatar/discuss.codechef.com/eitpw_03/32/24644_2.png) [@eitpw\_03](https://discuss.codechef.com/u/eitpw_03)\
**Post date:** [November 16, 2022, 5:35pm UTC](https://discuss.codechef.com/t/can-anyone-tell-what-is-wrong-in-this-code/104108/1 "2022-11-16T17:35:11Z")

</div>

**problem code : CNDY**

_I written a code and output matches with a given output but don’t understand how it shows wrong answer after submitting code._

below is my code 🙂

```auto
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here

	int t;
	cin>>t;
	
	while(t--){
	    int n;
	    int max=0;
	    int cnt=1;
	    cin>>n;
        
	    int a[2*n];
        
    for(int i=0;i<2*n;i++){
	        cin>>a[i];
	    }
	    
	sort(a,a+(2*n));
	
	for(int i=0;i<2*n-1;i++){
	    if(a[i]==a[i+1]){
	            cnt++;
	        
	       if(cnt>max){
	          max=cnt;  
	        }
	   }
	        
	 }
	    if(max<=2)
	    cout<<"yes"<<endl;
	    else cout<<"no"<<endl;
 }
	return 0;
}

```

---

<div class="post-metadata">

**Author:** ![termii](https://discuss.codechef.com/user_avatar/discuss.codechef.com/termii/32/355675_2.png) [@termii](https://discuss.codechef.com/u/termii)\
**Post date:** [November 16, 2022, 10:15pm UTC](https://discuss.codechef.com/t/can-anyone-tell-what-is-wrong-in-this-code/104108/2 "2022-11-16T22:15:02Z")

</div>

Testcase:

```auto
1
2
1 1 2 2

```

Expected output:

```auto
YES

```

Your Output:

```auto
NO

```

You are solving a slightly different problem. You check if the array contains at most 1 number twice. But you are meant to check if the array does not contain any number more than twice.

---

<div class="post-metadata">

**Author:** ![eitpw\_03](https://discuss.codechef.com/user_avatar/discuss.codechef.com/eitpw_03/32/24644_2.png) [@eitpw\_03](https://discuss.codechef.com/u/eitpw_03)\
**Post date:** [November 18, 2022, 3:04am UTC](https://discuss.codechef.com/t/can-anyone-tell-what-is-wrong-in-this-code/104108/3 "2022-11-18T03:04:04Z")

</div>

oh!!  
Thanks bro 😄  
I got it !!
