Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.2 kB
4
Indexable
   public static int[] vowels(String[] str, String[] query){

        int[] count = new int[str.length];
        int[] res = new int[query.length];

        HashSet<Character> v = new HashSet<>();
        v.add('a');
        v.add('e');
        v.add('i');
        v.add('o');
        v.add('u');

        String[] q = {};

        for (int i = 0; i < str.length; i++){
            System.out.println(str[i].charAt(0) + " " + str[i].charAt(str[i].length()-1));
            if (v.contains(str[i].charAt(0)) && v.contains(str[i].charAt(str[i].length()-1)))
                count[i]++;
        }

        for (int i = 0; i < query.length; i++){
            q = query[i].split("-");

            for (int j = Integer.valueOf(q[0]) - 1; j < Integer.valueOf(q[1]); j++){
                res[i] += count[j];
            }
        }

        return res;
    }
    public static void main(String[] args){
        // System.out.println("Hello World");

        String[] arr = { "aba", "bcb", "ece", "aa", "e"};
        String[] query = { "1-3", "2-5", "2-2"};
        int[] a = vowels(arr, query);
        
        for (int i : a){
            System.out.println(i);
        }
    }
}