FastPrepSort Words by a Custom Alphabet
Problems/Sort Words by a Custom Alphabet

Sort Words by a Custom Alphabet

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks the candidate to sort a word list using the letter order supplied by a dictionary. This practice version exposes that order as a 26-letter alphabet string and makes prefix handling and empty output explicit.

You are given a custom alphabet order and an array of lowercase words. Sort the words in dictionary order, but use the custom order for the letters.

To compare two words, find the first position where they differ. The word whose letter comes earlier in alphabet goes first. If one word is a prefix of the other (it matches the start of the other word), the shorter word comes first. Return the sorted words.

Function

sortWordsByAlphabet(alphabet: String, words: String[]) → String[]

Examples

Example 1

alphabet = "zyxwvutsrqponmlkjihgfedcba"words = ["apple","app","banana"]return = ["banana","app","apple"]

The alphabet is reversed, so b comes before a and banana goes first. The other two words both start with app, and app is a prefix of apple, so the shorter app comes next. The result is banana, app, apple.

Example 2

alphabet = "bacdefghijklmnopqrstuvwxyz"words = ["ab","aa","ba","b"]return = ["b","ba","ab","aa"]

In this alphabet, b comes before a, so the words starting with b go first. Between b and ba, b is a prefix of ba, so b comes first. Between ab and aa, the second letters differ and b ranks before a, so ab comes before aa. The result is b, ba, ab, aa.

Example 3

alphabet = "abcdefghijklmnopqrstuvwxyz"words = []return = []

An empty word array remains empty.

Constraints

  • alphabet contains each of the 26 lowercase English letters exactly once.
  • 0 <= words.length <= 100000.
  • Every word is nonempty and contains only lowercase English letters.
  • The total number of characters across words is at most 200000.

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

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Bank Account Balances (Part 2): Monthly ReconciliationStripe · PHONE SCREENStripe interview questions
  • Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
  • Top Ten Most Frequent Words in a BookRobinhood · PHONE SCREENRobinhood interview questions
  • Group AnagramsEPAM · PHONE SCREENEPAM interview questions
  • Aggregate Matching IPv4 Addresses Across ResponsesPinterest · PHONE SCREENPinterest interview questions
  • Diff Two Filesystem Hash TreesCursor · PHONE SCREENCursor interview questions
  • Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
  • Group AnagramsJFrog · PHONE SCREEN

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad VOs: 32 Experiences (Part 5 of 5)

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)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[] sortWordsByAlphabet(String alphabet, String[] words) {
        // Write your code here.
    }

}
Checking account…