You are viewing a single comment's thread. Return to all comments →
Java O(N)
public static List<String> weightedUniformStrings(String s, List<Integer> queries) { HashSet<Integer> set = new HashSet<>(); HashSet<Character> helper = new HashSet<>(); List<String> result = new ArrayList<>(); int weight = 0; for (char c : s.toCharArray()) { if (!helper.isEmpty() && !helper.contains(c)) { weight = 0; helper.clear(); } helper.add(c); weight += c - 'a' + 1; set.add(weight); } for (int q : queries) result.add(set.contains(q) ? "Yes" : "No"); return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
Java O(N)