Reported April 2022
ZipRecruitercounting

Count Words Formable from Letters

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 mistake that sinks most first attempts at this ZipRecruiter OA, reported in April 2022, is treating the letters string as a pool you drain across words. It isn't. Each word gets the full multiset fresh. The task is simple on paper: split text into maximal letter runs, lowercase everything, and count how many words fit inside the letter counts. It's a counting problem wearing a string-parsing costume. If you read it wrong, Example 1 returns 1 instead of 2 and you burn minutes debugging. StealthCoder sits invisibly as a safety net if you blank mid-assessment, but the logic here is short enough to own.

The problem

Split text into maximal English-letter words, ignoring punctuation. Count how many words can be formed from the case-insensitive letter multiset letters, using each supplied occurrence at most once per word.

Function
countFormableWords(text: String, letters: String) → int

Examples
Example 1
text = "Hello, hole! world."
letters = "helloo"
return = 2
Hello and hole are formable; world requires unavailable letters.
Example 2
text = "Cat dog"
letters = "tac"
return = 1
Cat is formable case-insensitively, while dog is not.

Constraints
0 <= text.length,letters.length <= 100000

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build a frequency array of 26 counts from letters, lowercased. Then scan text once, collecting consecutive alphabetic characters into a word. When you hit a non-letter or the end, check that word: count its letters and compare each against the letters array. If every count is within budget, increment the answer. The pitfall is resetting. Counts for a word must start from zero each time, and the letters budget must never be decremented permanently. Another trap is punctuation glued to words, like "Hello," so you must split on any non-letter, not just spaces. Also handle the empty-string edge cases at 0 length and the final word with no trailing delimiter. With text up to 100000 characters, a single pass is O(n) and fine. Per-word checking over 26 slots is cheap. If you freeze during the live OA, StealthCoder can hand you this structure in real time, but write the flush-at-end step yourself.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Count Words Formable from Letters 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Words Formable from Letters FAQ

What's the trick in the ZipRecruiter Count Words Formable problem?+

Treat the letters string as a fixed 26-slot frequency table that never changes. For each word, count its own letters and compare. Don't subtract from the shared pool, because each word is checked against the full multiset independently.

How hard is this OA question really?+

Easy. It's a counting and parsing problem with no clever algorithm. Most failures come from misreading the reuse rule or botching word splitting around punctuation. If you get those two right, it's a ten to fifteen minute solve.

How should I split the text into words?+

Don't split on spaces. Walk the string and treat any non-English-letter character as a delimiter. Build the current word from consecutive letters, evaluate it when a delimiter appears, and don't forget to evaluate the last word at the end of the string.

What edge cases should I test?+

Empty text, empty letters, text with only punctuation, mixed case like Cat versus tac, a word needing two of a letter when only one exists, and a final word with no trailing punctuation. Empty letters should return 0 unless there are no words anyway.

How do I prepare for this in 48 hours?+

Write it once from scratch with a 26-int array and a single pass. Then test Example 1 and 2 by hand. Also rehearse similar frequency-compare problems like ransom note, since the same check shows up in a lot of string OAs.

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