package algorithms.makinganagrams;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Solution {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String a = in.next();
		String b = in.next();
		System.out.println(numberNeeded(a, b));
	}

	static int numberNeeded(String first, String second) {
		Map<Character, Integer> charMap = getCharacterMap(first);

		int count = 0;

		for (char c : second.toCharArray()) {
			if (!charMap.containsKey(c) || charMap.containsKey(c) && charMap.get(c) == 0) {
				count++;
			} else {
				if (charMap.containsKey(c) && charMap.get(c) > 0) {
					Integer current = charMap.get(c);
					current--;
					charMap.put(c, current);
				}
			}
		}

		for (Integer value : charMap.values()) {
			count = count + value;
		}

		return count;
	}

	private static Map<Character, Integer> getCharacterMap(String value) {
		Map<Character, Integer> charMap = new HashMap<>();

		for (char c : value.toCharArray()) {
			if (!charMap.containsKey(c)) {
				charMap.put(c, 1);
			} else {
				Integer current = charMap.get(c);
				current++;
				charMap.put(c, current);
			}
		}

		return charMap;
	}
}

@@ -33,34 +33,8 @@
 s;%0A%0A
-import java.util.HashMap;%0A
 impo
@@ -76,16 +76,88 @@
 Scanner;
+%0Aimport java.util.function.Function;%0Aimport java.util.stream.Collectors;
 %0A%0Aclass 
@@ -351,19 +351,20 @@
 %09static 
-int
+long
  numberN
@@ -406,34 +406,29 @@
 %7B%0A%09%09Map%3C
-Character, 
 Integer
+, Long
 %3E charMa
@@ -458,19 +458,20 @@
 st);%0A%0A%09%09
-int
+long
  count =
@@ -478,28 +478,27 @@
  0;%0A%0A%09%09for (
-char
+int
  c : second.
@@ -687,34 +687,16 @@
 %09%09%09%09
-Integer current = 
 charMap.
 get(
@@ -695,45 +695,23 @@
 Map.
-get(c);%0A%09%09%09%09%09current--;%0A%09%09%09%09%09
+put(c, 
 charMap.
 put(
@@ -702,38 +702,34 @@
 (c, charMap.
-put(c, current
+get(c) - 1
 );%0A%09%09%09%09%7D%0A%09%09%09
@@ -741,94 +741,81 @@
 %0A%0A%09%09
-for (Integer value : charMap.values()) %7B%0A%09%09%09count = count + value;%0A%09%09%7D%0A%0A%09%09return count
+return charMap.values().stream().reduce(count, (acc, curr) -%3E acc + curr)
 ;%0A%09%7D
@@ -836,34 +836,29 @@
 tic Map%3C
-Character, 
 Integer
+, Long
 %3E getCha
@@ -889,276 +889,111 @@
 %7B%0A%09%09
-Map%3CCharacter, Integer%3E charMap = new HashMap%3C%3E();%0A%0A%09%09for (char c : value.toCharArray()) %7B%0A%09%09%09if (!charMap.containsKey(c)) %7B%0A%09%09%09%09charMap.put(c, 1);%0A%09%09%09%7D else %7B%0A%09%09%09%09Integer current = charMap.get(c);%0A%09%09%09%09current++;%0A%09%09%09%09charMap.put(c, current);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return charMap
+return value.chars().boxed().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
 ;%0A%09%7D

add test to making anagrams, replace map building with java 8 streams api