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.
same here. I was using arraylist too. Instead of using HashSet, after taking a look at editorial, I figured out I could have replaced hashmap with hashset.
importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);//ArrayList<Integer> posW = new ArrayList<>();Map<Integer,Integer>posW=newHashMap<>();/** Map<Character, Integer> allW = new HashMap<>(); int counter = 0; for(char i = 'a'; i <= 'z'; i++){ allW.put(i, ++counter); } */Strings=in.next();for(inti=0;i<s.length();i++){chartemp=s.charAt(i);intcounter=1;posW.put((temp-96)*counter,0);while(i+1<s.length()&&temp==s.charAt(i+1)){i++;counter++;posW.put((temp-96)*counter,0);}}/* for(int i = 0; i < posW.size(); i++){ System.out.print(posW.get(i)+", "); } System.out.println(); */intn=in.nextInt();for(inta0=0;a0<n;a0++){intx=in.nextInt();if(posW.containsKey(x)){System.out.println("Yes");}else{System.out.println("No");}}}}
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 →
same here. I was using arraylist too. Instead of using HashSet, after taking a look at editorial, I figured out I could have replaced hashmap with hashset.