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){// Write your code hereHashSet<Integer>set=newHashSet<>();Stack<Character>stack=newStack<>();List<String>result=newArrayList<>();intweight=0;for(charc:s.toCharArray()){if(!stack.isEmpty()&&stack.peek()!=c){weight=0;while(!stack.isEmpty())stack.pop();}stack.push(c);weight+=c-'a'+1;set.add(weight);}for(intq:queries){if(set.contains(q))result.add("Yes");elseresult.add("No");}returnresult;}}
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 →
Java solution using stack