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.
publicstaticintpickingNumbers(List<Integer>a){// Write your code hereintmax=Integer.MIN_VALUE;Map<Integer,List<Integer>>maps=newHashMap<>();for(Integere:a){if(maps.containsKey(e)){List<Integer>list=maps.get(e);list.add(e);maps.put(e,list);}else{List<Integer>list=newArrayList<>();list.addAll(a.stream().filter(element->element==e+1).collect(Collectors.toList()));maps.put(e,list);}}for(Map.Entry<Integer,List<Integer>>entry:maps.entrySet()){if(entry.getValue().size()+1>max){max=entry.getValue().size()+1;}}returnmax;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
my solution in java 8: