You are viewing a single comment's thread. Return to all comments →
Your solution is very inefficient.
Here I suggest you functional approach, better efficiency and readability.
Scanner sc = new Scanner(System.in); Map<String, Long> counterMap = Stream.generate(sc::next) .limit(sc.nextInt()) .collect(groupingBy(identity(), counting())); Stream.generate(sc::next) .limit(sc.nextInt()) .map(query -> counterMap.getOrDefault(query, 0L)) .forEach(System.out::println);
P.S. imports are omitted.
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
Your solution is very inefficient.
Here I suggest you functional approach, better efficiency and readability.
P.S. imports are omitted.