You are viewing a single comment's thread. Return to all comments →
public static List<String> weightedUniformStrings(String s, List<Integer> queries) { // Write your code here List<String> ans = new ArrayList<>(); HashSet<Integer> weights = new HashSet<>(); int currentweight = 0; char prevChar = ' '; for(int i = 0; i < s.length(); i++) { char currentChar = s.charAt(i); int charWeight = currentChar - 'a' + 1; if(currentChar == prevChar) { currentweight += charWeight; } else { currentweight = charWeight; } weights.add(currentweight); prevChar = currentChar; } for(int i : queries) { if(weights.contains(i)) { ans.add("Yes"); } else { ans.add("No"); } } return ans; }
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 →