# | Title | Solution | Time | Space | Difficulty | Note |
1136 | O(|V|+|E|) | O(|E|) | Medium | Premium, BFS, Topological Sort | ||
310 | O(n) | O(n) | Medium | BFS | ||
269 | O(n) | O(1) | Hard | Premium, BFS, DFS, Topological Sort, | ||
210 | O(|V|+|E|) | O(|E|) | Medium | BFS, Topological Sort, Kahn’s Algorithm | ||
1631 | O(n*m log(n*m)) | O(n*m) | Medium | Graph, Binary Search, DFS, BFS, Bi-BFS, Union Find, Dijkstra’s Algorithm | ||
787 | O(|E|+log(|V|)) | O(|E|) | Medium | BFS, Dijkstra’s Algorithm | ||
743 | O(|E|+log(|V|)) | O(|E|) | Medium | BFS, Dijkstra’s Algorithm | ||
1584 | O(n^2) | O(n) | Medium | Graph, Union Find, MST, Kruskal’s Algorithm | ||
994 | O(m*n) | O(m*n) | Medium | BFS, | ||
429 | O(n) | O(w) | Medium | Tree | ||
1091 | O(n^2) | O(n) | Medium | BFS, | ||
116 | O(n) | O(1) | Medium | Recursion | ||
797 | O(p+r*n) | O(n) | Medium | DFS | ||
1059 | O(n+e) | O(n+e) | Medium | Premium, DFS, Â | ||
332 | O(|V|+|E| log(|V|)) | O(|V|+|E|) | Hard | Graph, Hierholzer’s Algorithm | ||
133 | O(n) | O(n) | Medium | BFS | ||
1168 | O(n log(n)) | O(n) | Hard | Premium, Graph, Union Find | ||
399 | O(e + q) | O(n) | Medium | Graph, DFS, Union Find, Floyd-Warshall Algorithm | ||
1202 | O(n log(n)) | O(n) | Medium | DFS, Union Find | ||
1101 | O(n log(n)) | O(n) | Medium | Premium, Graph, Union Find | ||
323 | O(n) | O(n) | Medium | Premium, Hash Table, Union Find | ||
261 | O(|V|+|E|) | O(|V|+|E|) | Medium | Premium, BFS, Â | ||
547 | O(n^2) | O(n) | Medium | DFS, Union Find |
#1136) You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relationswhere relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCourseiand course nextCoursei: course prevCoursei has to be taken before course nextCoursei.
In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.
Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.
#269) There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you.
You are given a list of strings words from the alien language's dictionary, where the strings in words are sorted lexicographically by the rules of this new language.
Return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules. If there is no solution, return "". If there are multiple solutions, return any of them.
A string s is lexicographically smaller than a string t if at the first letter where they differ, the letter in s comes before the letter in t in the alien language. If the first min(s.length, t.length) letters are the same, then s is smaller if and only if s.length < t.length.
#1059) Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:
Return true if and only if all roads from source lead to destination.
#1168) There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.
For each house i, we can either build a well inside it directly with cost wells[i - 1] (note the -1 due to 0-indexing), or pipe in water from another well to it. The costs to lay pipes between houses are given by the array pipes where each pipes[j] = [house1j, house2j, costj] represents the cost to connect house1j and house2j together using a pipe. Connections are bidirectional, and there could be multiple valid connections between the same two houses with different costs.
Return the minimum total cost to supply water to all houses.
#1101) There are n people in a social group labeled from 0 to n - 1. You are given an array logs where logs[i] = [timestampi, xi, yi] indicates that xi and yi will be friends at the time timestampi.
Friendship is symmetric. That means if a is friends with b, then b is friends with a. Also, person a is acquainted with a person bif a is friends with b, or a is a friend of someone acquainted with b.
Return the earliest time for which every person became acquainted with every other person. If there is no such earliest time, return -1.
#323) You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.
Return the number of connected components in the graph.
#261) You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph.
Return true if the edges of the given graph make up a valid tree, and false otherwise.