fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. int main(){
  4. int t ;
  5. cin>>t;
  6. while(t--){
  7. bool isDone = false ;
  8. int n ;
  9. cin>>n ;
  10. string s ;
  11. cin>>s;
  12. map <string,int> mp;
  13. for(int i = 0 ; i< n-1 ; i++){
  14. string temp = s.substr(i,2);
  15. if(mp[temp] == 0)mp[temp] = i+1;
  16. // checking if there is already a pair exist or not if yes then
  17. // difference between their indexes should be greater than or equal to 2 else test as :- aaa will fail
  18. else if(mp[temp] + 2 <= i+1){
  19. cout<<"YES\n";
  20. isDone = true ;
  21. break;
  22. }
  23. }
  24. if(!isDone) cout<<"NO\n";
  25. }
  26. }
Success #stdin #stdout 0s 5320KB
stdin
6
10
codeforces
8
labacaba
5
uohhh
16
isthissuffixtree
1
x
4
momo
stdout
NO
YES
NO
YES
NO
YES