Weighted Uniform Strings

  • + 0 comments
    public static List<String> weightedUniformStrings(String s, List<Integer> queries) {
        // Write your code here
        List<Integer> output = new ArrayList<>();
        List<String> weight = new ArrayList<>();
        int n=0;
        for (int i = 0; i < s.length(); i+=n) {
            n=0;
            for (int j = i; j < s.length(); j++) {
                if (s.charAt(i)==s.charAt(j)) {
                    n++;
                }else{
                    j=s.length();
                }
            }
            for (int j = 1; j < n+1; j++) {
                output.add(j*((int)s.charAt(i)%96));
            }
        }
        for (Integer integer : queries) {
            if (output.contains(integer)) {
                weight.add("Yes");
            }else{
                weight.add("No");
            }
        }
        
        return weight;
        
        
    
        }