FastPrepValidate a Word Abbreviation
Problems/Validate a Word Abbreviation

Validate a Word Abbreviation

Salesforce logoSalesforce● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Salesforce onsite interview. Our version is about 99% the same as the reported question.

Given strings word and abbreviation, determine whether abbreviation is a valid abbreviation of word.

Read both strings from left to right:

  • A letter in abbreviation must equal the current letter in word.
  • A maximal run of decimal digits represents the number of letters to skip in word.
  • A number cannot have a leading zero.
  • A skip cannot move past the end of word.

The abbreviation is valid only when both inputs are consumed completely.

Function

validWordAbbreviation(word: String, abbreviation: String) → boolean

Examples

Example 1

word = "internationalization"abbreviation = "i12iz4n"return = true

The abbreviation keeps i, skips 12 letters, keeps i and z, skips 4 letters, and keeps the final n.

Example 2

word = "apple"abbreviation = "a2e"return = false

After matching a and skipping two letters, the abbreviation's e is compared with l, so the strings do not match.

Example 3

word = "substitution"abbreviation = "s010n"return = false

The numeric token begins with 0, so the abbreviation is invalid even though its numeric value could otherwise be parsed.

Constraints

  • word contains letters.
  • abbreviation contains letters and decimal digits.
  • Letter matching is case-sensitive.
  • Every numeric token fits in a signed 32-bit integer.

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

  • String CompressionShnoor International · ONSITE INTERVIEW
  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
  • Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
  • Reverse Vowels of a StringGoogle · ONSITE INTERVIEWGoogle interview questions
  • Valid Palindrome After NormalizationKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Count Binary SubstringsDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
  • Reverse A StringNVIDIA · ONSITE INTERVIEWNVIDIA 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 boolean validWordAbbreviation(String word, String abbreviation) {
        // Write your code here.
    }
}
Checking account…