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.
// Complete the freqQuery function below.staticList<Integer>freqQuery(List<List<Integer>>queries){List<Integer>result=newArrayList<>();List<Integer>data=newArrayList<>();HashMap<Integer,Function<Integer,Boolean>>mapa=newHashMap<>();mapa.put(1,o->data.add(o));mapa.put(2,o->data.remove(o));mapa.put(3,o->{Map<Integer,Long>counts=data.stream().collect(Collectors.groupingBy(e->e,Collectors.counting()));returnresult.add(counts.containsValue(newLong(o))?1:0);});queries.forEach(integers->{mapa.get(integers.get(0)).apply(integers.get(1));});returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Frequency Queries
You are viewing a single comment's thread. Return to all comments →
My solution using Java 8 Streams