Sort by Variable-Length Alphabet Tokens
Updated
Problem statement
alphabet lists language symbols from smallest to largest; each symbol is a nonempty string and lengths may vary. Every input word has exactly one tokenization into these symbols.
Sort words lexicographically by their token-rank sequences. If one sequence is a prefix of another, the shorter word comes first.
Function
sortTokenAlphabetWords(alphabet: String[], words: String[]) → String[]Examples
Example 1
alphabet = ["ba","aa","cb","abc","d","dd"]words = ["cbba","abccb","aaba","baaa"]return = ["baaa","aaba","cbba","abccb"]Each word has only one way to split into tokens. The first token of each word has rank 0, 1, 2 and 3 for baaa, aaba, cbba and abccb in that order, so that is the sorted order.
Constraints
- Every word is uniquely tokenizable.
- Total input length is at most
10^5.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Longest String ChainVisa · OAVisa interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Concatenated WordsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Balanced Parentheses with Sequential Left DeletionsGoogle · PHONE SCREENGoogle interview questions
- Word Break IIWex · PHONE SCREEN
- Word Break IIInMobi · PHONE SCREENInMobi interview questions
- Word Break II: All SentencesMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Palindrome with K DeletionsWhatNot · PHONE SCREENWhatNot interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)