FastPrepGenerate All Valid Word Abbreviations
Problems/Generate All Valid Word Abbreviations

Generate All Valid Word Abbreviations

Salesforce logoSalesforce● MediumFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report defines the full general-abbreviation search. This exercise returns the unique results in lexicographic order.

Given a lowercase word, generate every valid abbreviation of that word.

  • Each character is either kept literally or replaced by a count of consecutive abbreviated characters.
  • Adjacent abbreviated characters must be merged into one decimal count.
  • Every distinct abbreviation appears exactly once.

Return all abbreviations in ascending lexicographic order.

Function

generateAbbreviations(word: String) → String[]

Examples

Example 1

word = "ab"return = ["1b","2","a1","ab"]

The four keep-or-abbreviate choices produce 1b, 2, a1, and ab after sorting.

Example 2

word = "a"return = ["1","a"]

The single character can be abbreviated as 1 or kept as a.

Constraints

  • 1 <= word.length <= 15.
  • word contains lowercase English letters.
  • Lexicographic comparison uses ordinary character-code order.

More Salesforce Onsite Interview questions

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
  • Meeting Rooms IIONSITE INTERVIEW · Seen Oct 2026
  • Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
  • Choose Five Words with 25 Distinct LettersGoogle · ONSITE INTERVIEWGoogle interview questions
  • Generate Strings of Length at Least ThreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Insert Addition and Multiplication OperatorsPinterest · ONSITE INTERVIEWPinterest interview questions
  • Enumerate All SubsequencesInfosys · ONSITE INTERVIEWInfosys interview questions
  • Generate ParenthesesAmazon · ONSITE INTERVIEW
  • Beautiful ArrangementMathWorks · ONSITE INTERVIEWMathWorks interview questions
  • Generate ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Generate Palindromic PermutationsMotive · ONSITE INTERVIEWMotive interview questions
  • SubsetsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public String[] generateAbbreviations(String word) {
        // TODO: generate each abbreviation once and return the sorted results.
    }
}
Checking account…