FastPrepVerify Words Sorted by a Custom Alphabet
Problems/Verify Words Sorted by a Custom Alphabet

Verify Words Sorted by a Custom Alphabet

TrueFoundry logoTrueFoundry● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: given a list of words written with a scrambled alphabet, return whether the list is sorted in ascending order under that alphabet. You get n words, and the alphabet order is given as an array of characters in order. The example used cat, bat, tab with the alphabet C, B, A, T, and the output was true or false.

The report does not say how to compare a word with a longer word that starts with it, whether two equal words count as sorted, or how large the input can be. Here, the shorter word comes first, equal neighbors are allowed, and every letter is a lowercase letter listed in the alphabet.

Our version is about 95% the same as the reported question.

You are given an array of words, words, and an array of letters, alphabet. alphabet lists letters in a scrambled order: a letter that appears earlier in alphabet comes before every letter that appears later.

Compare two words letter by letter from the left. At the first position where they differ, the word whose letter comes earlier in alphabet is smaller. If there is no such position, the shorter word is smaller, and two identical words are equal.

Return true if words is sorted in ascending order under this alphabet, meaning every word is smaller than or equal to the word after it. Otherwise, return false.

Function

isSortedByAlphabet(words: String[], alphabet: char[]) → boolean

Examples

Example 1

words = ["cat","bat","tab"]alphabet = ["c","b","a","t"]return = true

The alphabet order is c, b, a, t.

"cat" and "bat" first differ at their first letter. c comes before b, so "cat" is smaller.

"bat" and "tab" also differ at their first letter. b comes before t, so "bat" is smaller. Every word is smaller than the next one, so the answer is true.

Example 2

words = ["tab","tab","tac"]alphabet = ["t","a","c","b"]return = false

The first two words are identical, which is allowed.

"tab" and "tac" first differ at their third letter: b and c. In this alphabet, c comes before b, so "tac" is smaller than "tab". A larger word comes before a smaller one, so the answer is false.

Example 3

words = ["ab","a"]alphabet = ["a","b"]return = false

The words have no differing position: "a" matches the start of "ab". So the shorter word, "a", is smaller.

Here "ab" comes first, so the answer is false.

Constraints

  • 1 <= words.length <= 1000
  • 1 <= words[i].length <= 100
  • 1 <= alphabet.length <= 26
  • alphabet contains distinct lowercase English letters.
  • Every letter of every words[i] appears in alphabet.

More TrueFoundry Phone Screen questions

  • Interview Slot BookingPHONE SCREEN · Seen Jul 2026
  • Versioned ArrayPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Most Frequent NameAmazon · PHONE SCREEN
  • Words with Repeated AnagramsThe Voleon Group · PHONE SCREEN
  • Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
  • Product Keyword SearchTesco · PHONE SCREEN
  • Character Frequencies Across Nested String ListsSnowflake · PHONE SCREENSnowflake interview questions
  • Neighboring Record IDsZipRecruiter · PHONE SCREENZipRecruiter interview questions
See TrueFoundry hiring insights
Saved
class Solution {
    public boolean isSortedByAlphabet(String[] words, char[] alphabet) {
        // Write your solution here.
    }
}
Checking account…