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<Integer>missingNumbers(List<Integer>arr,List<Integer>brr){// Write your code hereList<Integer>result=newArrayList<>();Map<Integer,Integer>freqArr=newHashMap<>();Map<Integer,Integer>freqBrr=newHashMap<>();for(intnum:arr){freqArr.put(num,freqArr.getOrDefault(num,0)+1);}for(intnum:brr){freqBrr.put(num,freqBrr.getOrDefault(num,0)+1);}for(Map.Entry<Integer,Integer>entry:freqBrr.entrySet()){intnum=entry.getKey();intfreqInBrr=entry.getValue();intfreqInArr=freqArr.getOrDefault(num,0);if(freqInBrr>freqInArr){result.add(num);}}Collections.sort(result);returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Missing Numbers
You are viewing a single comment's thread. Return to all comments →
Java