207. Course Schedule
Medium
There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [ai, bi]</code> indicates that you must take course <code>bi</code> first if you want to take course <code>ai</code>.
For example, the pair <code>[0, 1]</code>, indicates that to take course <code>0</code> you have to first take course <code>1</code>.
Return <code>true</code> if you can finish all courses. Otherwise, return <code>false</code>.
Example 1:
Example 2:
Constraints:
<code>1 <= numCourses <= 105</code>
<code>0 <= prerequisites.length <= 5000</code>
<code>prerequisites[i].length == 2</code>
<code>0 <= ai, bi < numCourses</code>
All the pairs prerequisites[i] are unique.
bfs
dfs
210. Course Schedule II
Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.
Example 3:
<code>1 <= numCourses <= 2000</code>
<code>0 <= prerequisites.length <= numCourses * (numCourses - 1)</code>
<code>ai != bi</code>
All the pairs <code>[ai, bi]</code> are distinct.
892 · Alien Dictionary
Algorithms
Description
There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of non-empty words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order of letters in this language.
You may assume all letters are in lowercase.
The dictionary is invalid, if a is prefix of b and b is appear before a.
If the order is invalid, return an empty string.
There may be multiple valid order of letters, return the smallest in normal lexicographical order
Example