FastPrepUnique Word Abbreviations
Problems/Unique Word Abbreviations

Unique Word Abbreviations

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the compression rule of prefix, count, and suffix, and its follow-up on uniqueness. Our version is about 94% the same as the reported question.

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.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Domain Weight CalculationAmazon · ONSITE INTERVIEW
  • Detect Blocked Chat PhrasesWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • File System PathsCapital One · ONSITE INTERVIEWCapital One interview questions
  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Extract Company Tickers from NewsSusquehanna International Group (SIG) · ONSITE INTERVIEWSusquehanna International Group (SIG) interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Fuzzy Word Lookup With One Misspelled LetterMeta · PHONE SCREENMeta interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] abbreviateWords(String[] words) {
        // Write your code here.
    }
}
Checking account…