Character Frequencies Across Nested String Lists
Learn this problemProblem statement
Given a two-level array of string groups, count the total number of occurrences of every character across every string.
Traverse the outer array from left to right, each inner array from left to right, and each string from left to right. Return the frequency map as a two-column String[][]. Each row must be [character, count], where character is a one-character string and count is its decimal frequency. Order rows by the first appearance of each character during that traversal.
Characters are case-sensitive, and spaces and punctuation are counted like any other printable ASCII character. Empty inner arrays and empty strings are allowed. If no character appears, return an empty matrix. Do not use a built-in frequency-counter utility such as Python's Counter.
Function
nestedCharacterFrequencies(groups: String[][]) → String[][]Examples
Example 1
groups = [["hello"],["world"]]return = [["h","1"],["e","1"],["l","3"],["o","2"],["w","1"],["r","1"],["d","1"]]The traversal first visits "hello" and then "world". It first discovers h, e, l, o, w, r, d; l occurs three times, o occurs twice, and every other character occurs once.
Example 2
groups = [["Aa",""],[],["!A"," a"]]return = [["A","2"],["a","2"],["!","1"],[" ","1"]]The empty string and empty inner array contribute no characters. Uppercase A and lowercase a are distinct, and the exclamation mark and space are counted in first-appearance order.
Example 3
groups = [[],[""],[]]return = []No string contains a character, so the frequency matrix is empty.
Constraints
0 <= groups.length <= 10^30 <= groups[i].length <= 10^3- Across all inner arrays, there are at most
10^4strings. - Across all strings, there are at most
2 * 10^5characters. - Every string contains only printable ASCII characters.
More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026
- Top Two Users by Total Purchase AmountPHONE SCREEN · Seen Jun 2026