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.
publicstaticList<String>weightedUniformStrings(Strings,List<Integer>queries){//process the weight for each uniform substring and store it in set USet<Integer>U=newHashSet<>();//store the total weight to account for substrings greater than 1inttotalWeight=0;for(inti=0;i<s.length();i++){//get the current weightintcurrentWeight=s.charAt(i)-96;//if the weight before it is the same, add the total weight to the setif(i>0&&s.charAt(i-1)==s.charAt(i)){totalWeight+=currentWeight;U.add(totalWeight);}else{totalWeight=currentWeight;U.add(currentWeight);}}//check if each query is in the setList<String>queryAccuracies=newArrayList<>();for(intquery:queries){if(U.contains(query))queryAccuracies.add("Yes");elsequeryAccuracies.add("No");}//return list of queriy accuraciesreturnqueryAccuracies;}
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 →
My Java solution: