Validate a Word Abbreviation
Updated
Problem statement
Given strings word and abbreviation, determine whether abbreviation is a valid abbreviation of word.
Read both strings from left to right:
- A letter in
abbreviationmust equal the current letter inword. - 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) → booleanExamples
Example 1
word = "internationalization"abbreviation = "i12iz4n"return = trueThe 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 = falseAfter 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 = falseThe numeric token begins with 0, so the abbreviation is invalid even though its numeric value could otherwise be parsed.
Constraints
wordcontains letters.abbreviationcontains 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