GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesAlien Alphabet

Gamified challenge · Topological sort

Alien Alphabet

words is a dictionary of lowercase words, already sorted in an alien alphabet that uses the same letters as English in some unknown order. Words are compared like in a normal dictionary: at the first position where they differ, the word with the earlier letter comes first, and a word comes before any longer word it is a prefix of.

Write alienOrder(words) that returns a string containing each letter that appears in the words exactly once, in an order that agrees with the sorted list. Any alphabet that fits passes. If no alphabet can produce this order (the clues contradict each other, or a word comes before its own prefix), return an empty string.

Example: ["wrt", "wrf", "er", "ett", "rftt"] gives the clues t < f, w < e, r < t and e < r, so the answer is "wertf".

Sign in to play Alien Alphabet

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account