2121B - B. Above the Clouds

import java.util.Scanner;

public class App {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] table = new int[26];
        for (int i = 0; i < n; ++i) {
            Boolean found = false;
            int len = Integer.parseInt(sc.nextLine());
            String s = sc.nextLine();
            char c1 = s.charAt(0);
            char c2 = s.charAt(len - 1);
            for (int j = 1; j < len - 1; ++j) {
                char c = s.charAt(j);
                if (c == c1 || c == c2 || ++table[c - 'a'] > 1) {
                    System.out.println("YES");
                    found = true;
                    break;
                }
            }
            if (!found) System.out.println("NO");
            Arrays.fill(table, 0);
         }
        sc.close();
    }
}
posted @ 2025-07-09 15:44  kayaker  阅读(12)  评论(0)    收藏  举报