상위 150개 인터뷰쉬움

외계인 사전

'Alien Dictionary' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

영어 알파벳을 사용하는 새로운 외계 언어가 있습니다. 그러나 편지의 순서는 당신에게 알려져 있지 않습니다.

외계어 사전에서 문자열 단어 목록이 제공됩니다. 여기서 단어의 문자열은 이 새로운 언어의 규칙에 따라 사전순으로 정렬됩니다.

새 언어의 규칙에 따라 사전순으로 오름차순으로 정렬된 새 외계 언어의 고유 문자 문자열을 반환합니다. 해결 방법이 없으면 ""를 반환합니다. 솔루션이 여러 개인 경우 그중 하나를 반환합니다.

alienOrder(words: List[str]) -> str 함수를 작성하세요.

제약
  • 1 <= len(words) <= 100
  • 1 <= len(words[i]) <= 100
  • words[i] consists of lowercase English letters

Example 1
Input
words = ["wrt","wrf","er","ett","rftt"]
Output
"wertf"
Explanation

From the sorted words, we can derive the relationships: 'w' -> 'e', 'r' -> 't', 't' -> 'f', etc.

Example 2
Input
words = ["z","x"]
Output
"zx"
Explanation

From "z" and "x", we know 'z' comes before 'x'.

Example 3
Input
words = ["z","x","z"]
Output
""
Explanation

The order is invalid because 'z' comes before 'x' and 'x' comes before 'z'.

Need a Hint?
세트나 힙과 같은 고급 그래프 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.