fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[]= {3,1,2,3,2};
  6. int n=sizeof(arr)/sizeof(arr[0]);
  7. int k=2;
  8. bool flag=false;
  9. for(int i=0;i<n;i++){
  10. for(int j=i+1;j<n;j++){
  11. if(arr[i]==arr[j]){
  12. if(j-i<=k)
  13. flag=true;
  14. }
  15. }
  16. }
  17. if(flag)
  18. cout<<"yes";
  19. else
  20. cout<<"no";
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
yes