Can Fit Word
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's Can Fit Word appeared in March 2024 OAs and it's a straightforward string problem that catches people off-guard because the solution is simpler than candidates expect. You're given a word and a set of character widths, and you need to determine if the word fits within a line of a given width. The trick isn't complex math or clever recursion. It's recognizing that you just sum up the widths of each character and compare to the limit. StealthCoder sits in the background as your safety net if you blank on parsing the width table during the live assessment.
Pattern and pitfall
This is a pure string iteration problem. You loop through each character in the word, look up its width in the provided table, accumulate the total, and return whether it's within bounds. The common pitfall is overcomplicating it: some candidates waste time thinking about word wrapping algorithms or dynamic programming when they should just be iterating and summing. The width table is usually a simple array or dictionary keyed by character. Edge cases to watch are empty strings, single characters, and verifying that every character in the word has a defined width. The pattern is string traversal and accumulation. Having StealthCoder available during the OA means if you hesitate on how to structure the width lookup or loop, you have a concrete template to fall back on.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Can Fit Word 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 StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as text justification. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google 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.
Can Fit Word FAQ
Is this problem really just summing character widths?+
Yes. No dynamic programming, no greedy selection, no complex logic. Read the word character by character, add up their widths from the table, and return true if the total fits. That's the whole pattern. If the problem statement seems to suggest something harder, re-read it.
What if a character doesn't have a defined width?+
The problem should guarantee all characters in the word have widths defined. If it doesn't, check the problem text again. If it's ambiguous, assume all printable ASCII characters are provided. Handle gracefully by returning false if any character is missing from the width map.
Does order of characters in the word matter?+
No. You're not rearranging or selecting a subset of characters. The word is fixed. You iterate it in order and sum the widths of whatever characters are there.
How do I parse the width input quickly?+
Most assessments give you a list of character-width pairs or a map. Build a dictionary or hash table from it in O(n) time. Then lookup each character during the main loop. If it's a 2D array of ASCII values and widths, index directly by ASCII code for instant O(1) access.
Is this problem still asked at Google in 2024?+
Yes, it was reported in March 2024. Google uses simple string problems as warm-ups and filtering checks. Don't dismiss it as too easy. The risk is leaving time on the table by second-guessing the solution or making careless mistakes in the loop.