Reported September 2025
Googlestring

Unique Word Abbreviations

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

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

Brute force dies fast here. Up to 1000 words, each up to 400 characters, and comparing every candidate abbreviation against every other word over and over adds up. That's the Google OA reported in September 2025: Unique Word Abbreviations. You get distinct lowercase words and must return the shortest-prefix abbreviation that's unique across the whole output, falling back to the original word if it doesn't get shorter. It's a string problem with a grouping trick underneath. If you blank on the approach during the live assessment, StealthCoder runs invisibly on your desktop as a safety net. Know the trick first, though.

The problem

Given an array of distinct lowercase words, return one unique abbreviation for every word in the same order.
An abbreviation keeps a nonempty prefix, replaces the omitted middle characters with their decimal count, and keeps the final character. For example, using a one-character prefix turns localization into l10n.
For each word, use the shortest prefix that makes its abbreviation different from every other returned abbreviation. If that abbreviation is not strictly shorter than the original word, return the original word instead.

Function
abbreviateWords(words: String[]) → String[]

Examples
Example 1
words = ["like","god","internal","me","internet","interval","intension","face","intrusion"]
return = ["l2e","god","internal","me","i6t","interval","inte4n","f2e","intr4n"]
Conflicting words receive longer prefixes. Short words or abbreviations that would not save space remain unchanged.
Example 2
words = ["apple","blade"]
return = ["a3e","b3e"]
The one-letter prefixes already distinguish the two abbreviations.

Constraints
1 <= words.length <= 1000
1 <= words[i].length <= 400
The words are distinct and contain only lowercase English letters.
The sum of all word lengths is at most 10^5.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Start with every word at prefix length 1 and build its abbreviation: prefix + count + last char. Group words by identical abbreviation in a hash map. Any group with more than one word is a conflict, so bump the prefix length for only those words and regroup. Repeat until no group has size above one. Each round only touches conflicting words, and prefix lengths never exceed word length, so the work stays bounded by the 10^5 total character limit. The faster alternative is a trie or sorting with longest-common-prefix against neighbors. The pitfall is the final check: if the abbreviation isn't strictly shorter than the word, return the word. Also watch words of length 1 or 2, where abbreviating never saves space. If the grouping loop trips you up live, StealthCoder is the hedge on the real OA.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Unique Word Abbreviations 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as word abbreviation. If you have time before the OA, drill that.

⏵ The honest play

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

Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Unique Word Abbreviations FAQ

What's the trick in the Google Unique Word Abbreviations problem?+

Group words by their current abbreviation using a hash map. Only words in groups larger than one need a longer prefix. Increase their prefix by one, regroup, and repeat. Finish by returning the original word whenever the abbreviation isn't strictly shorter than it.

How hard is this one really?+

It's a medium-to-hard string problem. The idea is simple, but the details bite: the iterative regrouping, the length check against the original word, and keeping runtime in line with the 10^5 total character limit. Clean code matters more than clever code.

Can I use a trie instead of repeated grouping?+

Yes. Group words by length and last character, then insert them into a trie that stores a count per node. The shortest prefix whose node count is one gives the unique abbreviation. Then apply the shorter-than-original check. It's cleaner but takes more setup than the hash map loop.

What edge cases should I test before submitting?+

Test words of length 1 and 2, which should come back unchanged. Test words sharing a long prefix like internal and interval, where the abbreviation doesn't shorten. Test a single-word input. Also confirm output order matches the input order, not the sorted order.

How do I prepare for this in 48 hours?+

Write the hash map regrouping solution from scratch once, then the trie version if time allows. Practice abbreviation building with off-by-one checks on the middle count. Run Example 1 by hand. Spend the rest of your time on general string and grouping problems.

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

OA at Google?
Invisible during screen share
Get it