We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is my Java 8 (15) solution, feel to to ask me if you have any questions.
publicstaticList<String>weightedUniformStrings(Strings,List<Integer>queries){Set<Integer>weightSet=newHashSet<>();//Perform founding weight set of the given string StringuniformStringRegex="([a-z])\\1*";Matcherm=Pattern.compile(uniformStringRegex).matcher(s);while(m.find()){Stringuniform=m.group();intcharacterWeight=uniform.charAt(0)-'a'+1;//find out the weights of the found uniform stringfor(intmultiplier=1;multiplier<=uniform.length();multiplier++){intweight=multiplier*characterWeight;weightSet.add(weight);}}//perform queryingList<String>results=newArrayList<>();for(intquery:queries){if(weightSet.contains(query)){results.add("Yes");}elseresults.add("No");}returnresults;}
Cookie support is required to access HackerRank
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 →
Here is my Java 8 (15) solution, feel to to ask me if you have any questions.