2
public int countCharacters(String[] words, String chars) {3
int[] freq = new int[26];4
for (int i = 0; i < chars.length(); i++) {5
// char - char is a kind of clever way to get the position of6
// the character in the alphabet. 'a' - 'a' would give you 0.7
// 'b' - 'a' would give you 1. 'c' - 'a' would give you 2, and so on.8
freq[chars.charAt(i) - 'a']++;12
for (String word : words) {13
int[] copy = Arrays.copyOf(freq, freq.length);15
for (int j = 0; j < word.length(); j++) {16
// decrement the frequency of this char in array for using17
// if there are less than 1 chance for using this character, invalid,18
// move to next word in words19
if (--copy[word.charAt(j) - 'a'] < 0) {25
result += word.length();