Source Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Codeforces {

    static FastReader input = new FastReader();
    static final int INF = (int) 1e9 + 20;
    static long xe, ye, d;
    
    public static void main(String[] args) throws NumberFormatException, IOException {
        int t = input.nextInt();
        for(int i=0; i<t; i++){
            String s = input.next();
            ArrayList<Integer> list = new ArrayList<>();
            boolean valid = true;
            for(int j=0; j<s.length(); j++){
                list.add(s.charAt(j)-'A');
            }
            Collections.sort(list);
            for(int j=1; j<list.size(); j++){
                if(list.get(j)>= 13 || list.get(j)-list.get(j-1) != 1){
                    valid = false;
                }
            }
            if(valid){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
            
        }
    }
    
    static class FastReader {
 
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            /*try {
             br = new BufferedReader(new FileReader(new File("travel_restrictions_validation_input.txt")));
             } catch (FileNotFoundException e) {
             e.printStackTrace();
             }*/
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() throws IOException {
            while (st == null || !st.hasMoreElements()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }
 
        int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }
 
        long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
 
        double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
 
        String nextLine() throws IOException {
            String str = "";
            str = br.readLine();
            return str;
        }
 
        boolean hasNext() throws IOException {
            return br.ready();
        }
    }
}
Copy
Well-indexed? Catwoman
Java 11
470 ms
34.4 MB
Accepted