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.
I used this logic for my Java 8 solution but failed 6/15 test cases. Could you help me check it out?
// Complete the freqQuery function below.staticList<Integer>freqQuery(List<int[]>queries){Map<Integer,Integer>countMap=newHashMap<Integer,Integer>();Map<Integer,Integer>freqMap=newHashMap<Integer,Integer>();List<Integer>answer=newArrayList();for(int[]i:queries){switch(i[0]){case1:countMap.compute(i[1],(k,v)->(v==null)?1:v+1);freqMap.compute(countMap.get(i[1]),(k,v)->(v==null)?1:v+1);freqMap.compute(countMap.get(i[1]-1),(k,v)->(v==null||v-1==0)?null:v-1);break;case2:countMap.compute(i[1],(k,v)->(v==null||v-1==0)?null:v-1);freqMap.compute(countMap.get(i[1]),(k,v)->(v==null)?1:v+1);freqMap.compute(countMap.get(i[1]+1),(k,v)->(v==null||v-1==0)?null:v-1);break;case3:if(freqMap.containsKey(i[1])&&freqMap.get(i[1])!=null){answer.add(1);}else{answer.add(0);}}}returnanswer;}
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 →
I used this logic for my Java 8 solution but failed 6/15 test cases. Could you help me check it out?