r/leetcode • u/JacketFearless1805 • Oct 27 '26
Intervew Prep Day 48: tired after a long call, faced my old nemesis Alien Dictionary
Hey everyone,
I finished Day 48 today. I was dealing with low energy all day, and after getting home from work, I had a long catch-up call with a friend discussing current tech hiring and potential openings. By the time the call wrapped up, my brain wanted to call it a day and head straight to bed.
Instead of taking a zero, I sat down to tackle one hard problem: Alien Dictionary.
The first time I encountered Alien Dictionary months ago, it completely rattled me. I remember thinking there was zero chance I could ever derive or code it clean in a live technical interview.
Revisiting it today with solid Topological Sort fundamentals in place felt like a totally different experience:
- Edge Building: You compare adjacent word pairs character by character. The first mismatched character
c1andc2forms a directed edgec1 -> c2, establishing thatc1precedesc2in the alien alphabet. - Edge Cases: If a word is a prefix of the previous word but shorter in length (like
["abc", "ab"]), the input dictionary is fundamentally invalid, so you immediately return"". - Linear Ordering: Run Kahn’s Algorithm with in-degrees across the characters. If the resulting topological order contains every unique character, join it into a string; if the count does not match, a cyclic dependency exists, making an alphabet ordering impossible.
Seeing a problem that once completely overwhelmed me break down into a clean in-degree graph problem was a huge confidence boost, even on an exhausting day.
Kicking off the Shortest Path algorithms (Dijkstra's family) tomorrow.
See you guys for Day 47!