You are viewing a single comment's thread. Return to all comments →
I did this but still tests 10,12,13 fail due to timeout. Please help
my solution :
static List freqQuery(List queries) {
HashMap<Integer,Integer> hash = new HashMap<Integer,Integer>(); List<Integer> retList = new ArrayList<Integer>(); for(int i=0;i<queries.size();i++) { int op = queries.get(i)[0]; int num = queries.get(i)[1]; if(op==1) { if(!hash.containsKey(num)) hash.put(num,1); else hash.put(num,hash.get(num)+1); } else if(op==2) { if(hash.containsKey(num)) { if(hash.get(num)<=1) hash.remove(num); else hash.put(num,hash.get(num)-1); } } else if(op==3) { if(hash.containsValue(num)){ retList.add(1); } else retList.add(0); } } return retList; }
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 did this but still tests 10,12,13 fail due to timeout. Please help
my solution :
static List freqQuery(List queries) {