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 // Youtube : The Adarsh 1M Set<Integer>hs = new HashSet<>(); int prev = 0; char cho = s.charAt(0); // Map<Character, Integer> mp = new HashMap<>(); for(char ch : s.toCharArray()) { int val = (ch-'a') + 1; if(ch == cho){ val = val+prev; prev = val; } else{ prev = val; } cho = ch; hs.add(val); // mp.put(ch, val); } List<String> ans = new ArrayList<>(); for(int num : queries) { if(hs.contains(num)) 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 →