Strings: Making Anagrams

  • + 6 comments

    In the same spirit here is my Java 8 solution for the lulz:

    public static int numberNeeded(String first, String second) {
            int[] freq = new int[26];
            first.chars().forEach((c) -> {
                freq[c - 97]++;
            });
            second.chars().forEach((c) -> {
                freq[c - 97]--;
            });
            return Arrays.stream(freq).map(Math::abs).sum();
    }