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.

The naming is a bit weird so I'll try my best to decipher it.

arrayChars is just an array of ints that represents the frequency of each char out of all 26 chars.

So arrayChars[x] is the char @ x.

Ex: arrayChars[0] = frequency of 'a'

If you notice the line above performs arrayChars[x]++;
Since the set has non-repeating elements, the frequency of the char will only increment by 1 if it exists in the string

Ex: 'aaaaaaabb' -> (add to Set) -> 'ab' -> arrayChars[0]++ and arrayChars[1]++

The final piece of the puzzle is numString. numString = N in the problem description.

Each (unique) char must exist N times, since there are N strings.

If we increment the freq of a char and the char's frequency is now greater than or equal to n, then we know that the char appeared in all the strings. We can increment the count of unique char's that appeared in all the strings.

## Gemstones

You are viewing a single comment's thread. Return to all comments →

if(arrayChars[x] >= numString){ count++;

Can anyone help me understand what is going on here?

The naming is a bit weird so I'll try my best to decipher it.

arrayChars is just an array of ints that represents the frequency of each char out of all 26 chars.

So arrayChars[x] is the char @ x.

Ex: arrayChars[0] = frequency of 'a'

If you notice the line above performs arrayChars[x]++; Since the set has non-repeating elements, the frequency of the char will only increment by 1 if it exists in the string

Ex: 'aaaaaaabb' -> (add to Set) -> 'ab' -> arrayChars[0]++ and arrayChars[1]++

The final piece of the puzzle is numString. numString = N in the problem description.

Each (unique) char must exist N times, since there are N strings.

If we increment the freq of a char and the char's frequency is now greater than or equal to n, then we know that the char appeared in all the strings. We can increment the count of unique char's that appeared in all the strings.

Hope that helped.