← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Meta SWE coding round, got a custom alphabet sorting problem. Pretty clean problem once you see the trick, but I fumbled around longer than I should have before the approach clicked.

Questions Asked (1)

Q1

Given a custom alphabet ordering and a list of words, determine whether the words are sorted in lexicographic order according to that custom alphabet rather than the standard English one.

Algorithms & Data Structures
Author's notes

The key move is building a rank lookup from the order string first, then just comparing adjacent word pairs.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, map each character in the custom alphabet to its rank (e.g., index in the alphabet string) to enable O(1) comparisons. Then, iterate through adjacent word pairs and compare them character by character using the custom ranks; if a mismatch is found, ensure the first word's character has a lower rank. Also handle the edge case where one word is a prefix of the other: the shorter word must come first.

Pro tip: Clarify whether the custom alphabet contains all 26 letters or just a subset, and whether words can contain characters outside the alphabet. Handling these edge cases upfront shows thoroughness and prevents incorrect assumptions.

1. Clarify assumptions and edge cases

Ask if the custom alphabet includes all letters, if words can have characters not in the alphabet, and if the list can be empty or have one word. Confirm that 'sorted' means non-decreasing order.

2. Build a rank map

Create a hash map or array that maps each character in the custom alphabet to its index (rank). This allows O(1) lookups during comparisons.

3. Compare adjacent words

Iterate through the list from i=0 to n-2. For each pair (words[i], words[i+1]), compare them character by character using the rank map to determine the correct order.

4. Handle prefix and mismatch cases

If a mismatch occurs, check if rank of char from first word < rank of char from second word; if not, return false. If one word is a prefix of the other, ensure the shorter word comes first; otherwise, return false.

5. Return result and analyze complexity

If all adjacent pairs are in order, return true. Discuss time complexity O(N*L) where N is number of words and L is max word length, and space complexity O(1) for the rank map (since alphabet size is constant).

Key Points to Mention

  • Mapping characters to ranks using a hash map or array for O(1) comparisons.
  • Iterating through adjacent word pairs and comparing character by character.
  • Handling the case where one word is a prefix of another: the shorter word must come first.
  • Edge cases: empty list, single word, words with characters not in the custom alphabet.
  • Time complexity: O(N * L) where N is number of words and L is average length; space complexity: O(1) for the rank map.
  • Early termination: return false as soon as an out-of-order pair is found.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.