You are viewing a single comment's thread. Return to all comments →
public static List weightedUniformStrings(String s, List queries) { // Write your code here
//-------------------------------- // Regex pattern String pattern = "(.)\\1*"; // Create a Pattern object Pattern compiledPattern = Pattern.compile(pattern); // Create a Matcher object Matcher matcher = compiledPattern.matcher(s); // List to store the result ArrayList<String> result = new ArrayList<>(); // Find all matches while (matcher.find()) { result.add(matcher.group()); } //----------------------------------- List<String> list=new ArrayList<>(); Map<Character,Integer> map=new LinkedHashMap<>(); char ch[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; for(int i=0;i<ch.length;i++){ map.put(ch[i], i+1); } Set<Integer> set=new LinkedHashSet<>(); int length; int value; for(int i=0;i<result.size();i++){ length=result.get(i).length(); value=map.get(result.get(i).charAt(0)); for(int j=1;j<=length;j++){ set.add(j*value); } } boolean b; for(int i=0;i<queries.size();i++){ b= set.contains(queries.get(i)); if(b){ list.add("Yes"); }else{ list.add("No"); } } return list; }
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
public static List weightedUniformStrings(String s, List queries) { // Write your code here