FastPrepAlien Dictionary
Problems/Alien Dictionary

Alien Dictionary

Amazon logoAmazon● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Amazon Experience 32 reports this problem by name, from an onsite interview. Our function signature and fixed rules are the same as in our existing, tested version of this problem.

An alien language uses the lowercase English letters, but their order is unknown. You are given an array words that is intended to be sorted from smallest to largest according to that alien alphabet.

Return the lexicographically smallest ordering of every distinct character that makes the dictionary order valid. If no such ordering exists, return the empty string.

For two different words, compare characters from left to right. At the first position where they differ, the character in the earlier word must come before the character in the later word. If all compared characters match, the shorter word must come first.

Each precedence relationship must be counted only once, even if multiple adjacent word pairs imply it.

Function

alienOrder(words: String[]) → String

Examples

Example 1

words = ["wrt","wrf","er","ett","rftt"]return = "wertf"

The adjacent pairs establish w < e, e < r, r < t, and t < f, so the only valid order is wertf.

Example 2

words = ["za","zb","ca","cb"]return = "abzc"

The constraints are a < b and z < c. Several orders are valid, and abzc is the lexicographically smallest one.

Example 3

words = ["abc","ab"]return = ""

A longer word cannot appear before its exact prefix in a sorted dictionary, so no valid alphabet exists.

Constraints

  • 1 <= words.length <= 500
  • 1 <= words[i].length <= 100
  • The total number of characters across all words is at most 10^4.
  • Every word contains only lowercase English letters.

More Amazon Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Alien DictionaryByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Infer a Lexicographically Smallest Alien AlphabetMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Alien DictionaryBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Letter Order from a Sorted Word ListRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Can Subsequences Share One Master Sequence?Google · ONSITE INTERVIEWGoogle interview questions
  • Password From Ordering HintsRogo · ONSITE INTERVIEW
  • Alien DictionaryIntuit · OAIntuit interview questions
  • Recover an Alien Alphabet from Sorted WordsOpenAI · PHONE SCREENOpenAI interview questions
  • Validate CSV References and Field DependenciesStripe · PHONE SCREENStripe interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public String alienOrder(String[] words) {
      // write your code here
    }
}
Checking account…