Reported September 2024
ZipRecruiterhash table

Most Frequent Word across Grouped Arrays

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The ZipRecruiter OA reported in September 2024 hides one small rule in the statement: matching is case-sensitive, so "Apple" and "apple" are two different words. That's the whole problem in one line. You flatten the grouped arrays, count each word, and pick the winner with a lexicographic tiebreak. It's a hash-table counting problem dressed up as a string question. If your nerves spike and the tiebreak logic slips, StealthCoder is the invisible safety net running during the live OA. Most people will finish this one in minutes if they stay calm and read the empty-input case.

The problem

Count every word occurrence across all rows of groups. Return the word with highest frequency, breaking ties lexicographically. Matching is case-sensitive. Return an empty string when there are no words.

Function
mostFrequentWord(groups: String[][]) → String

Examples
Example 1
groups = [["a","b"],["a","c"]]
return = "a"
Word a occurs twice across rows.
Example 2
groups = [["beta"],["alpha"]]
return = "alpha"
Lexicographic order resolves equal frequency.

Constraints
0 <= groups.length <= 10000
The total number of words is at most 100000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a single pass with a hash map. Loop over every row, loop over every word, increment the count. Then scan the map once, keeping the best word. Replace it when the count is higher, or when the count is equal and the word is lexicographically smaller. That's O(n) time for n total words, which is fine at 100000. The common pitfalls are small. Don't lowercase anything, since matching is case-sensitive. Don't sort the whole map when one scan does it. Handle groups = [] and rows that are empty by returning an empty string when nothing was counted. Compare strings with plain ordinal comparison, not a locale-aware one. If you blank on the tiebreak during the live OA, StealthCoder can show you the compact version so you aren't debugging under pressure.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Most Frequent Word across Grouped Arrays cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Most Frequent Word across Grouped Arrays FAQ

How hard is the ZipRecruiter most frequent word question really?+

It's easy. It's a frequency count with a tiebreak. The difficulty is only in the details: case-sensitive matching, lexicographic ties, and returning an empty string for empty input. If you've used a hash map before, you can finish it quickly.

What's the trick to this problem?+

Use one hash map to count words across all rows, then do a single scan for the best entry. Update the best when the count is higher, or equal with a smaller word. No sorting is needed, which keeps it linear.

Do I need to lowercase the words?+

No. The statement says matching is case-sensitive, so "A" and "a" count separately. Lowercasing is the most common mistake on this one, and it would fail hidden tests that mix cases.

What edge cases should I test?+

Test groups as an empty array, groups containing only empty rows, a tie between two words, and mixed-case words. All of the empty cases must return an empty string. Example 2 with beta and alpha covers the tiebreak.

How do I prepare in 48 hours?+

Write this once from memory: nested loop, map increment, then a scan with a tiebreak comparison. Then do two or three similar counting problems like top-k frequent words. That covers the pattern. Don't spend time on advanced topics for this one.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it