Welsh Custom Alphabet Sort
Updated
Problem statement
Sort words using this Welsh alphabet of tokens:
a, b, c, ch, d, dd, e, f, ff, g, ng, h, i, l, ll, m, n, o, p, ph, r, rh, s, t, th, u, w, y
The tokens ch, dd, ff, ng, ll, ph, rh, and th are single alphabet symbols. Tokenize each word greedily using these two-letter symbols before single letters, then compare token ranks from left to right. If one token sequence is a prefix of another, the shorter word comes first.
Function
sortWelshWords(words: String[]) → String[]Examples
Example 1
words = ["ddr","nah","dea","dd","ngah"]return = ["dea","dd","ddr","ngah","nah"]d precedes dd; dd is a prefix of ddr; and ng precedes n in the supplied token alphabet.
Example 2
words = ["ca","cha","da","dda"]return = ["ca","cha","da","dda"]The leading tokens follow c < ch < d < dd.
Constraints
1 <= words.length <= 10^5.- Every word is nonempty, lowercase, and can be tokenized by the alphabet above.
- The total number of characters is at most
2 * 10^5.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE 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
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
- Top K Movies by Play Count from CSV DataTubi · PHONE SCREEN
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsWorkday · PHONE SCREEN
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Query JSON Records with WHERE and ORDER BYGitHub · ONSITE INTERVIEW
- Bank Account Balances (Part 2): Monthly ReconciliationStripe · PHONE SCREENStripe interview questions
- Sort by Odd-Position Digit SumPelatro · ONSITE INTERVIEW