1766B - Notepad - CodeForces Solution


implementation *1000

Please click on ads to support us..

Python Code:

import sys
from os import path


def input():
    return sys.stdin.readline().strip()


def solve(n, s):
    for i in range(2, n-1):
        if s[:i].count(s[i:i+2]):
            print("YES")
            return
        else:
            continue
    print("NO")


def main():
    testcases = int(input())      for _ in range(testcases):
        n = int(input())
        s = input()
        solve(n, s)


if __name__ == "__main__":

    if path.exists('Tests'):
        sys.stdin = open("Tests/input_1.txt", "r")
        sys.stdout = open("Tests/output_1a.txt", "w")

    main()

C++ Code:

#include<bits/stdc++.h>
using  namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int pos=0;
        map<string,int> m;
        for(int i=0;i<n-1;i++)
        {
            string temp="";
            temp.push_back(s[i]);
            temp.push_back(s[i+1]);
            // cout<<"curr subs="<<temp<<" ";
            if(m.find(temp)==m.end())
            {
                m[temp]=i;
            }
            else
            {
                if(m[temp]!=i-1)
                {
                    pos=1;
                    break;
                }
            }
        }
        if(pos==1)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
}


Comments

Submit
0 Comments
More Questions

1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph
404A - Valera and X
908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64